|
1 /* |
|
2 * Copyright (c) 2002-2004 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 // INCLUDE FILES |
|
20 |
|
21 #define __INCLUDE_CAPABILITY_NAMES__ |
|
22 |
|
23 #include "IniFileHelper.h" |
|
24 #include "constants.h" |
|
25 #include "debug.h" |
|
26 |
|
27 |
|
28 #include <e32capability.h> |
|
29 #include <centralrepository.h> |
|
30 #include <utf.h> |
|
31 |
|
32 |
|
33 // EXTERNAL DATA STRUCTURES |
|
34 // EXTERNAL FUNCTION PROTOTYPES |
|
35 // CONSTANTS |
|
36 |
|
37 static const TChar KNullDataIndicator = '-'; |
|
38 static const TInt KMaxCapCount = 7; |
|
39 static const TInt KMaxCapCountSidExist = 3; |
|
40 |
|
41 // MACROS |
|
42 // LOCAL CONSTANTS AND MACROS |
|
43 // MODULE DATA STRUCTURES |
|
44 // LOCAL FUNCTION PROTOTYPES |
|
45 |
|
46 |
|
47 // ==================== LOCAL FUNCTIONS ================= |
|
48 // ================= MEMBER FUNCTIONS ======================= |
|
49 |
|
50 // ----------------------------------------------------------------------------- |
|
51 // CSecuritySetting::AddSid() |
|
52 // ----------------------------------------------------------------------------- |
|
53 // |
|
54 |
|
55 CSecuritySetting::CSecuritySetting() |
|
56 { |
|
57 iSidExistWr = iSidExistRd = EFalse; |
|
58 |
|
59 for ( TInt i(0); i < KMaxCapCount; i++) |
|
60 { |
|
61 iCapWr[i] = iCapRd[i] = TUint8(ECapability_None); |
|
62 } |
|
63 } |
|
64 |
|
65 |
|
66 // ----------------------------------------------------------------------------- |
|
67 // CSecuritySetting::SecurityString() |
|
68 // ----------------------------------------------------------------------------- |
|
69 // |
|
70 TDesC& CSecuritySetting::SecurityString( TDes &aSecurityString) |
|
71 { |
|
72 using namespace IniConstants; |
|
73 |
|
74 aSecurityString.Zero(); |
|
75 TBuf<30> cap; |
|
76 |
|
77 TInt capCount = KMaxCapCount; |
|
78 |
|
79 if ( iSidExistRd) |
|
80 { |
|
81 |
|
82 //create sid_wr=0x000000 string, where 0x000000 is aSecurityId |
|
83 TBuf< KUidLengthSet> name; |
|
84 name.Num( iSidRd.iUid, EDecimal); |
|
85 |
|
86 aSecurityString.Append( KReadAccessSidString ); |
|
87 aSecurityString.Append( _L("=") ); |
|
88 aSecurityString.Append( name ); |
|
89 aSecurityString.Append(' '); |
|
90 |
|
91 capCount = KMaxCapCountSidExist; |
|
92 } |
|
93 |
|
94 for ( TInt i(0); i < capCount; i++) |
|
95 { |
|
96 if ( iCapRd[ i] != TUint8(ECapability_None) ) |
|
97 { |
|
98 aSecurityString.Append( KReadAccessCapString); |
|
99 aSecurityString.Append('='); |
|
100 cap.Copy( ConvertCapToStr( iCapRd[ i], iDefaultTypeRd)); |
|
101 aSecurityString.Append( cap); |
|
102 aSecurityString.Append(' '); |
|
103 } |
|
104 } |
|
105 |
|
106 capCount = KMaxCapCount; |
|
107 if ( iSidExistWr) |
|
108 { |
|
109 |
|
110 //create sid_wr=0x000000 string, where 0x000000 is aSecurityId |
|
111 TBuf< KUidLengthSet> name; |
|
112 name.Num( iSidWr.iUid, EDecimal); |
|
113 |
|
114 aSecurityString.Append( KWriteAccessSidString ); |
|
115 aSecurityString.Append( _L("=") ); |
|
116 aSecurityString.Append( name ); |
|
117 aSecurityString.Append(' '); |
|
118 |
|
119 capCount = KMaxCapCountSidExist; |
|
120 } |
|
121 |
|
122 for ( TInt i(0); i < capCount; i++) |
|
123 { |
|
124 if ( iCapWr[ i] != TUint8(ECapability_None) ) |
|
125 { |
|
126 aSecurityString.Append( KWriteAccessCapString); |
|
127 aSecurityString.Append('='); |
|
128 cap.Copy( ConvertCapToStr( iCapWr[ i], iDefaultTypeWr)); |
|
129 aSecurityString.Append( cap); |
|
130 aSecurityString.Append(' '); |
|
131 } |
|
132 } |
|
133 |
|
134 |
|
135 return aSecurityString; |
|
136 } |
|
137 |
|
138 |
|
139 // ----------------------------------------------------------------------------- |
|
140 // CSecuritySetting::ContainsSecuritySettings() |
|
141 // ----------------------------------------------------------------------------- |
|
142 // |
|
143 TBool CSecuritySetting::ContainsSecuritySettings() |
|
144 { |
|
145 return iSidExistWr || iSidExistRd || iCapWr[0] != TUint8(ECapability_None) || iCapRd[0] != TUint8(ECapability_None); |
|
146 } |
|
147 |
|
148 |
|
149 // ----------------------------------------------------------------------------- |
|
150 // CSecuritySetting::CheckAccess() |
|
151 // ----------------------------------------------------------------------------- |
|
152 // |
|
153 TBool CSecuritySetting::CheckAccess( const RMessage2& aMessage, TAccessType aAccessType) |
|
154 { |
|
155 TBool retVal = ETrue; |
|
156 |
|
157 if ( aAccessType == EReadAccess || aAccessType == EAccessBoth) |
|
158 { |
|
159 TInt capCount = KMaxCapCount; |
|
160 if ( iSidExistRd) |
|
161 { |
|
162 capCount = KMaxCapCountSidExist; |
|
163 if ( aMessage.SecureId().iId != iSidRd.iUid) |
|
164 { |
|
165 return EFalse; |
|
166 } |
|
167 } |
|
168 |
|
169 for ( TInt i(0); i < capCount; i++) |
|
170 { |
|
171 if ( iCapRd[ i] != TUint8(ECapability_None)) |
|
172 { |
|
173 if ( !aMessage.HasCapability( TCapability( iCapRd[ i]), KSuppressPlatSecDiagnosticMagicValue)) |
|
174 { |
|
175 return EFalse; |
|
176 } |
|
177 } |
|
178 |
|
179 } |
|
180 } |
|
181 |
|
182 if ( aAccessType == EWriteAccess || aAccessType == EAccessBoth) |
|
183 { |
|
184 TInt capCount = KMaxCapCount; |
|
185 if ( iSidExistWr) |
|
186 { |
|
187 capCount = KMaxCapCountSidExist; |
|
188 if ( aMessage.SecureId().iId != iSidWr.iUid) |
|
189 { |
|
190 return EFalse; |
|
191 } |
|
192 } |
|
193 |
|
194 for ( TInt i(0); i < capCount; i++) |
|
195 { |
|
196 if ( iCapWr[ i] != TUint8(ECapability_None)) |
|
197 { |
|
198 if ( !aMessage.HasCapability( TCapability( iCapWr[ i]), KSuppressPlatSecDiagnosticMagicValue)) |
|
199 { |
|
200 return EFalse; |
|
201 } |
|
202 } |
|
203 |
|
204 } |
|
205 } |
|
206 |
|
207 return retVal; |
|
208 } |
|
209 |
|
210 |
|
211 |
|
212 // ----------------------------------------------------------------------------- |
|
213 // CSecuritySetting::AddSid() |
|
214 // ----------------------------------------------------------------------------- |
|
215 // |
|
216 KSettingType CSecuritySetting::Type() |
|
217 { |
|
218 return iType; |
|
219 } |
|
220 |
|
221 |
|
222 // ----------------------------------------------------------------------------- |
|
223 // CSecuritySetting::AddSid() |
|
224 // ----------------------------------------------------------------------------- |
|
225 // |
|
226 TInt CSecuritySetting::AddSid( TUid aUid) |
|
227 { |
|
228 if ( iSidExistWr) |
|
229 { |
|
230 return KErrAlreadyExists; |
|
231 } |
|
232 |
|
233 //enable and set sid |
|
234 iSidWr = aUid; |
|
235 iSidExistWr = ETrue; |
|
236 |
|
237 return KErrNone; |
|
238 } |
|
239 |
|
240 // ----------------------------------------------------------------------------- |
|
241 // CSecuritySetting::RemoveSid() |
|
242 // ----------------------------------------------------------------------------- |
|
243 // |
|
244 TInt CSecuritySetting::RemoveSid() |
|
245 { |
|
246 //disable sid... |
|
247 iSidExistWr = EFalse; |
|
248 |
|
249 return KErrNone; |
|
250 } |
|
251 |
|
252 void CSecuritySetting::CopyCapabilities( CSecuritySetting* aSetting) |
|
253 { |
|
254 //Copy all capabilities from parameter object to this object |
|
255 iSidExistWr = aSetting->iSidExistWr; |
|
256 iSidWr = aSetting->iSidWr; |
|
257 iSidExistRd = aSetting->iSidExistRd; |
|
258 iSidRd = aSetting->iSidRd; |
|
259 |
|
260 for ( TInt i(0); i < KMaxCapCount; i++) |
|
261 { |
|
262 iCapRd[i] = aSetting->iCapRd[i]; |
|
263 iCapWr[i] = aSetting->iCapWr[i]; |
|
264 } |
|
265 } |
|
266 |
|
267 |
|
268 // ----------------------------------------------------------------------------- |
|
269 // CSecuritySetting::RemoveSid() |
|
270 // ----------------------------------------------------------------------------- |
|
271 // |
|
272 |
|
273 TInt CSecuritySetting::ReadCaps( TLex& aLex) |
|
274 { |
|
275 //read capablities, format: cap_type=cap_value |
|
276 using namespace IniConstants; |
|
277 |
|
278 TLex lex( aLex); |
|
279 lex.SkipSpace(); |
|
280 TInt err( KErrNone); |
|
281 |
|
282 //read until TLex reaches Eos... |
|
283 while ( !lex.Eos() && err == KErrNone) |
|
284 { |
|
285 //Mark start point |
|
286 TLexMark16 mark; |
|
287 lex.Mark( mark); |
|
288 lex.SkipSpace(); |
|
289 |
|
290 //get next token, contains capability type |
|
291 TPtrC token = lex.NextToken();; |
|
292 TPtrC typePtr( token); |
|
293 TPtrC capOrSid; |
|
294 |
|
295 //format could be "cap_type=..." or "cap_type =...", try to locate '='-mark from token |
|
296 TInt index = token.Locate('='); |
|
297 |
|
298 if ( index >= 0) |
|
299 { |
|
300 typePtr.Set( token.Left( index)); |
|
301 token.Set( token.Mid( index + 1)); |
|
302 } |
|
303 |
|
304 //read capabilities from. There could be max 3 caps separated with ',' |
|
305 TBool capOrSidDetected = EFalse; |
|
306 TBool ready = EFalse; |
|
307 do |
|
308 { |
|
309 //read new token if current token is empty |
|
310 if ( !token.Length()) |
|
311 { |
|
312 TLexMark subMark; |
|
313 lex.Mark( subMark); |
|
314 |
|
315 token.Set( lex.NextToken()); |
|
316 |
|
317 //if token contains only ',', then get new one |
|
318 if ( token.Length() == 1 && token[0] == ',') |
|
319 { |
|
320 token.Set( lex.NextToken()); |
|
321 } |
|
322 |
|
323 //check if capability type changes (e.g. cap_wr -> cap_rd) |
|
324 TPtrC ptr( token); |
|
325 TInt index = token.Locate('='); |
|
326 if ( index >= 0) |
|
327 { |
|
328 ptr.Set( token.Left(index)); |
|
329 } |
|
330 |
|
331 if ( ptr.CompareF( KReadAccessSidString) == 0 || |
|
332 ptr.CompareF( KReadAccessCapString) == 0 || |
|
333 ptr.CompareF( KWriteAccessSidString) == 0 || |
|
334 ptr.CompareF( KWriteAccessCapString) == 0 ) |
|
335 { |
|
336 token.Set( KNullDesC); |
|
337 lex.UnGetToMark( subMark); |
|
338 |
|
339 if ( !capOrSidDetected) |
|
340 { |
|
341 return KErrCorrupt; |
|
342 } |
|
343 |
|
344 ready = ETrue; |
|
345 continue; |
|
346 } |
|
347 } |
|
348 |
|
349 //read capability or SID |
|
350 if ( token.Length() ) |
|
351 { |
|
352 //rome ','-mark if exist |
|
353 TInt index = token.Locate(','); |
|
354 if ( index >= 0 ) |
|
355 { |
|
356 capOrSid.Set( token.Left( index )); |
|
357 token.Set( token.Mid( index + 1)); |
|
358 } |
|
359 else |
|
360 { |
|
361 capOrSid.Set( token); |
|
362 token.Set( KNullDesC); |
|
363 } |
|
364 |
|
365 //and cap or SID found add it to the setting |
|
366 if ( capOrSid.Length()) |
|
367 { |
|
368 capOrSidDetected = ETrue; |
|
369 err = AddSecurityAttributes( typePtr, capOrSid); |
|
370 } |
|
371 } |
|
372 else |
|
373 { |
|
374 ready = ETrue; |
|
375 } |
|
376 |
|
377 } while ( !ready && err == KErrNone); |
|
378 |
|
379 lex.SkipSpace(); |
|
380 } |
|
381 |
|
382 return err; |
|
383 } |
|
384 |
|
385 |
|
386 // ----------------------------------------------------------------------------- |
|
387 // CSecuritySetting::AddSecurityAttributes() |
|
388 // ----------------------------------------------------------------------------- |
|
389 // |
|
390 TInt CSecuritySetting::AddSecurityAttributes( const TDesC& aType, const TDesC& aValue) |
|
391 { |
|
392 using namespace IniConstants; |
|
393 |
|
394 TInt err = KErrGeneral; |
|
395 |
|
396 if ( KWriteAccessCapString == aType ) |
|
397 { |
|
398 TUint8 cap; |
|
399 if ( ConvertStrToCap( aValue, cap, iDefaultTypeWr) != KErrNone ) |
|
400 { |
|
401 return KErrGeneral; |
|
402 } |
|
403 err = AddWriteCap( cap ); |
|
404 } |
|
405 else if ( KReadAccessCapString == aType ) |
|
406 { |
|
407 TUint8 cap; |
|
408 if ( ConvertStrToCap( aValue, cap, iDefaultTypeRd) != KErrNone ) |
|
409 { |
|
410 return KErrGeneral; |
|
411 } |
|
412 err = AddReadCap( cap ); |
|
413 } |
|
414 else if ( KReadAccessSidString == aType) |
|
415 { |
|
416 if ( !iSidExistRd ) |
|
417 { |
|
418 if ( KErrNone == ConvertStrToSid( aValue, iSidRd)) |
|
419 { |
|
420 iSidExistRd = ETrue; |
|
421 err = KErrNone; |
|
422 } |
|
423 } |
|
424 } |
|
425 else if ( KWriteAccessSidString == aType) |
|
426 { |
|
427 if ( !iSidExistWr ) |
|
428 { |
|
429 if ( KErrNone == ConvertStrToSid( aValue, iSidWr)) |
|
430 { |
|
431 iSidExistWr = ETrue; |
|
432 err = KErrNone; |
|
433 } |
|
434 } |
|
435 } |
|
436 |
|
437 return err; |
|
438 } |
|
439 |
|
440 |
|
441 |
|
442 |
|
443 // ----------------------------------------------------------------------------- |
|
444 // CSecuritySetting::ConvertStrToCab() |
|
445 // ----------------------------------------------------------------------------- |
|
446 // |
|
447 TInt CSecuritySetting::ConvertStrToSid( const TDesC& aStr, TUid& aValue) |
|
448 { |
|
449 TLex lex( aStr); |
|
450 |
|
451 TRadix radix = EDecimal; |
|
452 if( lex.Peek()=='0') |
|
453 { |
|
454 lex.Inc(); |
|
455 if( lex.Peek().GetLowerCase()=='x') |
|
456 { |
|
457 lex.Inc(); |
|
458 radix = EHex; |
|
459 } |
|
460 else |
|
461 { |
|
462 lex.UnGet(); |
|
463 } |
|
464 } |
|
465 |
|
466 TUint32 value; |
|
467 TInt err = lex.Val( value, radix); |
|
468 aValue.iUid = value; |
|
469 return err; |
|
470 } |
|
471 |
|
472 |
|
473 // ----------------------------------------------------------------------------- |
|
474 // CSecuritySetting::ConvertStrToCab() |
|
475 // ----------------------------------------------------------------------------- |
|
476 // |
|
477 TInt CSecuritySetting::ConvertStrToCap( const TDesC& aCab, TUint8& aCapValue, KDefaultType& aType) |
|
478 { |
|
479 |
|
480 TBuf8<40> cap; |
|
481 cap.Append( aCab); |
|
482 cap.LowerCase(); |
|
483 |
|
484 if ( cap.CompareF( IniConstants::KAccessAlwaysPass ) == 0) |
|
485 { |
|
486 aType = EAlwaysPass; |
|
487 aCapValue = TUint8(ECapability_None); |
|
488 return KErrNone; |
|
489 } |
|
490 |
|
491 if ( cap.CompareF( IniConstants::KAccessAlwaysFail ) == 0) |
|
492 { |
|
493 aType = EAlwaysFail; |
|
494 aCapValue = TUint8(ECapability_None); |
|
495 return KErrNone; |
|
496 } |
|
497 |
|
498 |
|
499 for ( TInt i(0); i < ECapability_Limit; i++) |
|
500 { |
|
501 TPtrC8 ptr((const TUint8 *) CapabilityNames[i]); |
|
502 |
|
503 TBool compareResult = ETrue; |
|
504 for ( TInt j(0); j < ptr.Length(); j++) |
|
505 { |
|
506 TChar ptrChar( ptr[j]); |
|
507 TChar aCabChar( aCab[j]); |
|
508 ptrChar.LowerCase(); |
|
509 aCabChar.LowerCase(); |
|
510 |
|
511 if ( ptrChar != aCabChar ) |
|
512 { |
|
513 compareResult = EFalse; |
|
514 break; |
|
515 } |
|
516 } |
|
517 |
|
518 |
|
519 if ( compareResult ) |
|
520 { |
|
521 aCapValue = i; |
|
522 return KErrNone; |
|
523 } |
|
524 } |
|
525 |
|
526 return KErrNotFound; |
|
527 } |
|
528 |
|
529 |
|
530 // ----------------------------------------------------------------------------- |
|
531 // CSecuritySetting::ConvertCabToStr() |
|
532 // ----------------------------------------------------------------------------- |
|
533 // |
|
534 const TPtrC8 CSecuritySetting::ConvertCapToStr( TUint8 aCab, KDefaultType& aType) |
|
535 { |
|
536 if ( aCab == TUint8(ECapability_None)) |
|
537 { |
|
538 if ( aType == EAlwaysPass) |
|
539 { |
|
540 return IniConstants::KAccessAlwaysPass; |
|
541 } |
|
542 else |
|
543 { |
|
544 return IniConstants::KAccessAlwaysFail; |
|
545 } |
|
546 } |
|
547 |
|
548 return (const TUint8 *)CapabilityNames[ aCab]; |
|
549 } |
|
550 |
|
551 // ----------------------------------------------------------------------------- |
|
552 // CSecuritySetting::SetWriteCab() |
|
553 // ----------------------------------------------------------------------------- |
|
554 // |
|
555 TInt CSecuritySetting::AddWriteCap( TUint8 aCab) |
|
556 { |
|
557 TInt capCount = KMaxCapCount; |
|
558 if ( iSidExistWr) |
|
559 { |
|
560 capCount = KMaxCapCountSidExist; |
|
561 } |
|
562 |
|
563 for ( TInt i(0); i < capCount; i++) |
|
564 { |
|
565 if ( iCapWr[i] == TUint8(ECapability_None) ) |
|
566 { |
|
567 iCapWr[i] = aCab; |
|
568 return KErrNone; |
|
569 } |
|
570 } |
|
571 |
|
572 return KErrGeneral; |
|
573 } |
|
574 |
|
575 |
|
576 // ----------------------------------------------------------------------------- |
|
577 // CSecuritySetting::SetReadeCab() |
|
578 // ----------------------------------------------------------------------------- |
|
579 // |
|
580 TInt CSecuritySetting::AddReadCap( TUint8 aCab) |
|
581 { |
|
582 TInt capCount = KMaxCapCount; |
|
583 if ( iSidExistWr) |
|
584 { |
|
585 capCount = KMaxCapCountSidExist; |
|
586 } |
|
587 |
|
588 for ( TInt i(0); i < capCount; i++) |
|
589 { |
|
590 if ( iCapWr[i] == TUint8(ECapability_None) ) |
|
591 { |
|
592 iCapRd[i] = aCab; |
|
593 return KErrNone; |
|
594 } |
|
595 } |
|
596 |
|
597 return KErrGeneral; |
|
598 } |
|
599 |
|
600 |
|
601 |
|
602 // ----------------------------------------------------------------------------- |
|
603 // CSecuritySetting::Set() |
|
604 // |
|
605 // ----------------------------------------------------------------------------- |
|
606 // |
|
607 void CSecuritySetting::Set(const TDesC8& aDes, ECapTypes aCapType) |
|
608 { |
|
609 TBool *sidExist = &iSidExistRd; |
|
610 TUid *sid = &iSidRd; |
|
611 TUint8 *cap = iCapRd; |
|
612 KDefaultType *defaultType = &iDefaultTypeRd; |
|
613 |
|
614 if ( aCapType == EWriteCaps ) |
|
615 { |
|
616 sidExist = &iSidExistWr; |
|
617 sid = &iSidWr; |
|
618 cap = iCapWr; |
|
619 defaultType = &iDefaultTypeWr; |
|
620 } |
|
621 |
|
622 //check that string length match to TSecurity policy size |
|
623 if ( aDes.Length() == sizeof( TSecurityPolicy)) |
|
624 { |
|
625 //offsets are coming from TSecurityPolicy class |
|
626 TUint8 type = aDes[0]; |
|
627 *sidExist = EFalse; |
|
628 *defaultType = EAlwaysPass; |
|
629 |
|
630 switch ( type ) |
|
631 { |
|
632 case TSecurityPolicy::ETypeFail : |
|
633 *defaultType = EAlwaysFail; |
|
634 case TSecurityPolicy::ETypePass : |
|
635 { |
|
636 cap[0] = TUint8(ECapability_None); |
|
637 cap[1] = TUint8(ECapability_None); |
|
638 cap[2] = TUint8(ECapability_None); |
|
639 TInt32* uidRef = (TInt32*) (&cap[4]); |
|
640 *uidRef = TInt32(ECapability_None); |
|
641 } |
|
642 break; |
|
643 case TSecurityPolicy::ETypeS3 : |
|
644 { |
|
645 TInt32* uidRef = (TInt32*) (aDes.Ptr() + 4); |
|
646 sid->iUid = *uidRef; |
|
647 *sidExist = ETrue; |
|
648 } |
|
649 //break is not needed -> caps are read in next case statement |
|
650 case TSecurityPolicy::ETypeC3 : |
|
651 { |
|
652 for ( TInt i(0); i < 3; i++) |
|
653 { |
|
654 cap[i] = aDes[i+1]; |
|
655 } |
|
656 } |
|
657 break; |
|
658 case TSecurityPolicy::ETypeC7 : |
|
659 { |
|
660 for ( TInt i(0); i < KMaxCapCount; i++) |
|
661 { |
|
662 cap[i] = aDes[i+1]; |
|
663 } |
|
664 } |
|
665 break; |
|
666 default: |
|
667 { |
|
668 for ( TInt i(0); i < KMaxCapCount; i++) |
|
669 { |
|
670 cap[i] = TUint8(ECapability_None); |
|
671 } |
|
672 |
|
673 *sidExist = EFalse; |
|
674 } |
|
675 break; |
|
676 } |
|
677 } |
|
678 else |
|
679 { |
|
680 for ( TInt i(0); i < KMaxCapCount; i++) |
|
681 { |
|
682 cap[i] = TUint8(ECapability_None); |
|
683 *defaultType = EAlwaysPass; |
|
684 } |
|
685 *sidExist = EFalse; |
|
686 } |
|
687 } |
|
688 |
|
689 |
|
690 // ----------------------------------------------------------------------------- |
|
691 // CSecuritySetting::Package() |
|
692 // |
|
693 // ----------------------------------------------------------------------------- |
|
694 // |
|
695 void CSecuritySetting::Package( TDes8& aPackage, ECapTypes aCapType) const |
|
696 { |
|
697 const TBool *sidExist = &iSidExistRd; |
|
698 const TUid *sid = &iSidRd; |
|
699 const TUint8 *cap = iCapRd; |
|
700 const KDefaultType *defaultType = &iDefaultTypeRd; |
|
701 |
|
702 if ( aCapType == EWriteCaps ) |
|
703 { |
|
704 sidExist = &iSidExistWr; |
|
705 sid = &iSidWr; |
|
706 cap = iCapWr; |
|
707 defaultType = &iDefaultTypeWr; |
|
708 } |
|
709 |
|
710 TUint8 type = TSecurityPolicy::ETypePass; |
|
711 |
|
712 if ( *defaultType == EAlwaysFail) |
|
713 { |
|
714 type = TSecurityPolicy::ETypeFail; |
|
715 } |
|
716 |
|
717 |
|
718 TUint8 * package = const_cast<TUint8*>( aPackage.Ptr()); |
|
719 |
|
720 for ( TInt i(0); i < KMaxCapCount; i++) |
|
721 { |
|
722 package[i+1]= cap[i]; |
|
723 } |
|
724 |
|
725 if ( *sidExist ) |
|
726 { |
|
727 TInt32* uidRef = (TInt32*) (package + 4); |
|
728 *uidRef = sid->iUid; |
|
729 |
|
730 type = TSecurityPolicy::ETypeS3; |
|
731 } |
|
732 else if ( cap[0] != TUint8(ECapability_None)) |
|
733 { |
|
734 if ( cap[3] != TUint8(ECapability_None)) |
|
735 { |
|
736 type = TSecurityPolicy::ETypeC7; |
|
737 } |
|
738 else |
|
739 { |
|
740 type = TSecurityPolicy::ETypeC3; |
|
741 } |
|
742 } |
|
743 |
|
744 |
|
745 |
|
746 package[0] = type; |
|
747 } |
|
748 |
|
749 |
|
750 // ----------------------------------------------------------------------------- |
|
751 // CSecuritySetting::SetWr() |
|
752 // |
|
753 // ----------------------------------------------------------------------------- |
|
754 // |
|
755 void CSecuritySetting::SetWr(const TDesC8& aDes) |
|
756 { |
|
757 Set( aDes, EWriteCaps); |
|
758 } |
|
759 |
|
760 // ----------------------------------------------------------------------------- |
|
761 // CSecuritySetting::PackageWr() |
|
762 // ----------------------------------------------------------------------------- |
|
763 // |
|
764 void CSecuritySetting::PackageWr( TDes8& aPackage) const |
|
765 { |
|
766 Package( aPackage, EWriteCaps); |
|
767 } |
|
768 |
|
769 // ----------------------------------------------------------------------------- |
|
770 // CSecuritySetting::SetRd() |
|
771 // ----------------------------------------------------------------------------- |
|
772 // |
|
773 void CSecuritySetting::SetRd(const TDesC8& aDes) |
|
774 { |
|
775 Set( aDes, EReadCaps); |
|
776 } |
|
777 |
|
778 // ----------------------------------------------------------------------------- |
|
779 // CSecuritySetting::PackageRd() |
|
780 // ----------------------------------------------------------------------------- |
|
781 // |
|
782 void CSecuritySetting::PackageRd( TDes8& aPackage) const |
|
783 { |
|
784 Package( aPackage, EReadCaps); |
|
785 } |
|
786 |
|
787 |
|
788 |
|
789 // ----------------------------------------------------------------------------- |
|
790 // CSecuritySetting::ExternalizeL() |
|
791 // ----------------------------------------------------------------------------- |
|
792 // |
|
793 void CSecuritySetting::ExternalizeL(RWriteStream& aStream) const |
|
794 { |
|
795 //write read- and write-security policies |
|
796 TBuf8< sizeof(TSecurityPolicy)> buf; |
|
797 buf.SetLength( sizeof(TSecurityPolicy)); |
|
798 PackageRd( buf); |
|
799 aStream << buf; |
|
800 PackageWr( buf); |
|
801 aStream << buf; |
|
802 } |
|
803 |
|
804 // ----------------------------------------------------------------------------- |
|
805 // CSecuritySetting::InternalizeL() |
|
806 // ----------------------------------------------------------------------------- |
|
807 // |
|
808 void CSecuritySetting::InternalizeL(RReadStream& aStream) |
|
809 { |
|
810 |
|
811 //read read-security policies |
|
812 HBufC8* readPolicy = HBufC8::NewLC( aStream, 5000) ; |
|
813 SetRd( *readPolicy); |
|
814 CleanupStack::PopAndDestroy( readPolicy) ; |
|
815 |
|
816 |
|
817 //read write-security policies |
|
818 HBufC8* writePolicy = HBufC8::NewLC( aStream, 5000) ; |
|
819 SetWr( *writePolicy); |
|
820 CleanupStack::PopAndDestroy( writePolicy) ; |
|
821 } |
|
822 |
|
823 |
|
824 |
|
825 |
|
826 // ----------------------------------------------------------------------------- |
|
827 // CRangeMeta::CRangeMeta() |
|
828 // ----------------------------------------------------------------------------- |
|
829 // |
|
830 CRangeMeta::CRangeMeta() |
|
831 { |
|
832 } |
|
833 |
|
834 |
|
835 // ----------------------------------------------------------------------------- |
|
836 // CRangeMeta::CRangeMeta() |
|
837 // ----------------------------------------------------------------------------- |
|
838 // |
|
839 |
|
840 CRangeMeta::CRangeMeta( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask, TUint32 aMeta) |
|
841 : iStart( aRangeStart), iEnd( aRangeEnd), iMask( aMask), iMeta( aMeta) |
|
842 { |
|
843 if ( iMask ) |
|
844 { |
|
845 iType = EMaskSetting; |
|
846 } |
|
847 else |
|
848 { |
|
849 iType = ERangeSetting; |
|
850 } |
|
851 } |
|
852 |
|
853 // ----------------------------------------------------------------------------- |
|
854 // CRangeMeta::Type() |
|
855 // ----------------------------------------------------------------------------- |
|
856 // |
|
857 KSettingType CRangeMeta::Type() |
|
858 { |
|
859 return iType; |
|
860 } |
|
861 |
|
862 |
|
863 // ----------------------------------------------------------------------------- |
|
864 // CRangeMeta::Start() |
|
865 // ----------------------------------------------------------------------------- |
|
866 // |
|
867 TUint32 CRangeMeta::Start() const |
|
868 { |
|
869 return iStart; |
|
870 } |
|
871 |
|
872 // ----------------------------------------------------------------------------- |
|
873 // CRangeMeta::End() |
|
874 // ----------------------------------------------------------------------------- |
|
875 // |
|
876 TUint32 CRangeMeta::End() const |
|
877 { |
|
878 return iEnd; |
|
879 } |
|
880 |
|
881 // ----------------------------------------------------------------------------- |
|
882 // CRangeMeta::Mask() |
|
883 // ----------------------------------------------------------------------------- |
|
884 // |
|
885 TUint32 CRangeMeta::Mask() const |
|
886 { |
|
887 return iMask; |
|
888 } |
|
889 |
|
890 |
|
891 |
|
892 // ----------------------------------------------------------------------------- |
|
893 // CRangeMeta::NewL() |
|
894 // ----------------------------------------------------------------------------- |
|
895 // |
|
896 CRangeMeta* CRangeMeta::NewL( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask, TUint32 aMeta) |
|
897 { |
|
898 CRangeMeta * self = new (ELeave) CRangeMeta( aRangeStart, aRangeEnd, aMask, aMeta); |
|
899 |
|
900 return self; |
|
901 } |
|
902 |
|
903 |
|
904 // ----------------------------------------------------------------------------- |
|
905 // CRangeMeta::NewL() |
|
906 // ----------------------------------------------------------------------------- |
|
907 // |
|
908 CRangeMeta* CRangeMeta::NewL( TLex& aSecurityString) |
|
909 { |
|
910 CRangeMeta * setting = new (ELeave) CRangeMeta(); |
|
911 |
|
912 if ( KErrNone != setting->ReadRangeSetting( aSecurityString)) |
|
913 { |
|
914 if ( KErrNone != setting->ReadMaskSetting( aSecurityString)) |
|
915 { |
|
916 delete setting; |
|
917 setting = 0; |
|
918 } |
|
919 } |
|
920 |
|
921 |
|
922 return setting; |
|
923 } |
|
924 |
|
925 // ----------------------------------------------------------------------------- |
|
926 // CRangeMeta::ReadSetting() |
|
927 // ----------------------------------------------------------------------------- |
|
928 // |
|
929 TInt CRangeMeta::ReadRangeSetting( TLex& aSecurityString) |
|
930 { |
|
931 //Read range meta setting, format: 0x1234 0x1234 0x1234 (start end meta) |
|
932 //mask meta setting, format: 0x1234 mask=0x1234 0x01234 (value mask meta) |
|
933 //set mark to start point |
|
934 TLexMark16 mark; |
|
935 aSecurityString.SkipSpaceAndMark( mark); |
|
936 |
|
937 //read next token |
|
938 TPtrC token = aSecurityString.NextToken(); |
|
939 |
|
940 //shoud be a number |
|
941 TLex firstValue( token); |
|
942 if ( KErrNone != TIniFileHelper::ReadUNumber( iStart, firstValue ) || !firstValue.Eos()) |
|
943 { |
|
944 //and if not, abort evaluation and restore lex position |
|
945 aSecurityString.UnGetToMark( mark); |
|
946 return KErrGeneral; |
|
947 } |
|
948 |
|
949 //skip spaces and get next token |
|
950 aSecurityString.SkipSpace(); |
|
951 token.Set( aSecurityString.NextToken()); |
|
952 |
|
953 //masksetting?? |
|
954 TInt index = token.FindC( IniConstants::KMask); |
|
955 |
|
956 if ( index >= 0 ) |
|
957 { |
|
958 //should be in a following format mask=0x1234 |
|
959 //locate '=' |
|
960 index = token.Locate('='); |
|
961 |
|
962 if ( index >= 0 ) |
|
963 { |
|
964 //if '=' included in first token |
|
965 |
|
966 if ( index == ( token.Length() - 1)) |
|
967 { |
|
968 token.Set( aSecurityString.NextToken()); |
|
969 } |
|
970 else |
|
971 { |
|
972 token.Set( token.Mid( index + 1)); |
|
973 } |
|
974 } |
|
975 else |
|
976 { |
|
977 //next token contains '='-mark |
|
978 |
|
979 token.Set( aSecurityString.NextToken()); |
|
980 |
|
981 index = token.Locate('='); |
|
982 if ( index >= 0 && token.Length() > 1) |
|
983 { |
|
984 token.Set( token.Mid( index + 1)); |
|
985 } |
|
986 else |
|
987 { |
|
988 token.Set( aSecurityString.NextToken()); |
|
989 } |
|
990 } |
|
991 } |
|
992 |
|
993 //also next token should be number |
|
994 TLex secondValue( token); |
|
995 if ( KErrNone != TIniFileHelper::ReadUNumber( iEnd, secondValue) || !secondValue.Eos()) |
|
996 { |
|
997 //and if not, abort evaluation and restore lex position |
|
998 aSecurityString.UnGetToMark( mark); |
|
999 return KErrGeneral; |
|
1000 } |
|
1001 |
|
1002 //skip spaces and get next token |
|
1003 aSecurityString.SkipSpace(); |
|
1004 token.Set( aSecurityString.NextToken()); |
|
1005 |
|
1006 //also next token should be number |
|
1007 TLex thirdValue( token); |
|
1008 if ( KErrNone != TIniFileHelper::ReadUNumber( iMeta, thirdValue) || !thirdValue.Eos()) |
|
1009 { |
|
1010 //and if not, abort evaluation and restore lex position |
|
1011 aSecurityString.UnGetToMark( mark); |
|
1012 return KErrGeneral; |
|
1013 } |
|
1014 |
|
1015 return KErrNone; |
|
1016 } |
|
1017 |
|
1018 |
|
1019 // ----------------------------------------------------------------------------- |
|
1020 // CRangeSetting::ReadMaskSetting() |
|
1021 // ----------------------------------------------------------------------------- |
|
1022 // |
|
1023 |
|
1024 TInt CRangeMeta::ReadMaskSetting( TLex& aSecurityString) |
|
1025 { |
|
1026 using namespace IniConstants; |
|
1027 //Read mask (format = 0x1234 mask=01234 caps.... |
|
1028 |
|
1029 //Skip spaces and set start mark |
|
1030 TLexMark16 mark; |
|
1031 aSecurityString.SkipSpaceAndMark( mark); |
|
1032 |
|
1033 //read first token value |
|
1034 TPtrC token = aSecurityString.NextToken(); |
|
1035 TLex value( token); |
|
1036 |
|
1037 //token should be number |
|
1038 if ( KErrNone != TIniFileHelper::ReadUNumber( iStart, value) || !value.Eos()) |
|
1039 { |
|
1040 //abort evaluation and restore lex position |
|
1041 aSecurityString.UnGetToMark( mark); |
|
1042 return KErrGeneral; |
|
1043 } |
|
1044 |
|
1045 //next token(s) should contain mask definition |
|
1046 aSecurityString.SkipSpace(); |
|
1047 token.Set( aSecurityString.NextToken()); |
|
1048 |
|
1049 //try found the mask identifier |
|
1050 TInt index = token.FindF( KMask); |
|
1051 if ( index == KErrNotFound ) |
|
1052 { |
|
1053 //and if not found, abort evaluation and restore lex position |
|
1054 aSecurityString.UnGetToMark( mark); |
|
1055 return KErrGeneral; |
|
1056 } |
|
1057 |
|
1058 //locate '='-mark, it could be part current token or in next token |
|
1059 index = token.Locate('='); |
|
1060 |
|
1061 if ( index == KErrNotFound) |
|
1062 { |
|
1063 //get next token and try locate '='-mark |
|
1064 token.Set( aSecurityString.NextToken()); |
|
1065 index = token.Locate('='); |
|
1066 |
|
1067 if ( index == KErrNotFound ) |
|
1068 { |
|
1069 //and if not found, abort evaluation and restore lex position |
|
1070 aSecurityString.UnGetToMark( mark); |
|
1071 return KErrGeneral; |
|
1072 } |
|
1073 } |
|
1074 else |
|
1075 { |
|
1076 token.Set( token.Mid(4)); |
|
1077 } |
|
1078 |
|
1079 //if token length is more than 1, it must contain also mask-value |
|
1080 if ( token.Length() > 1 ) |
|
1081 { |
|
1082 //remove '='-mark |
|
1083 token.Set( token.Mid(1)); |
|
1084 } |
|
1085 else |
|
1086 { |
|
1087 //get next token, it must contain mask-value |
|
1088 token.Set( aSecurityString.NextToken()); |
|
1089 } |
|
1090 |
|
1091 //read mask value |
|
1092 TLex maskValue( token); |
|
1093 if ( KErrNone != TIniFileHelper::ReadUNumber( iMask, maskValue) || !maskValue.Eos()) |
|
1094 { |
|
1095 //if fails, abort evaluation and restore lex position |
|
1096 aSecurityString.UnGetToMark( mark); |
|
1097 return KErrGeneral; |
|
1098 } |
|
1099 |
|
1100 //skip spaces and get next token |
|
1101 aSecurityString.SkipSpace(); |
|
1102 token.Set( aSecurityString.NextToken()); |
|
1103 |
|
1104 //also next token should be number |
|
1105 TLex thirdValue( token); |
|
1106 if ( KErrNone != TIniFileHelper::ReadUNumber( iMeta, thirdValue) || !thirdValue.Eos()) |
|
1107 { |
|
1108 //and if not, abort evaluation and restore lex position |
|
1109 aSecurityString.UnGetToMark( mark); |
|
1110 return KErrGeneral; |
|
1111 } |
|
1112 |
|
1113 return KErrNone; |
|
1114 } |
|
1115 |
|
1116 |
|
1117 // ----------------------------------------------------------------------------- |
|
1118 // CRangeMeta::ExternalizeL() |
|
1119 // ----------------------------------------------------------------------------- |
|
1120 // |
|
1121 void CRangeMeta::ExternalizeL(RWriteStream& aStream) const |
|
1122 { |
|
1123 aStream << iStart; |
|
1124 aStream << iEnd; |
|
1125 aStream << iMask; |
|
1126 aStream << iMeta; |
|
1127 } |
|
1128 |
|
1129 // ----------------------------------------------------------------------------- |
|
1130 // CRangeMeta::InternalizeL() |
|
1131 // ----------------------------------------------------------------------------- |
|
1132 // |
|
1133 void CRangeMeta::InternalizeL(RReadStream& aStream) |
|
1134 { |
|
1135 aStream >> iStart; |
|
1136 aStream >> iEnd; |
|
1137 aStream >> iMask; |
|
1138 aStream >> iMeta; |
|
1139 |
|
1140 if ( iMask ) |
|
1141 { |
|
1142 iType = EMaskSetting; |
|
1143 } |
|
1144 else |
|
1145 { |
|
1146 iType = ERangeSetting; |
|
1147 } |
|
1148 |
|
1149 RDEBUG_4( "CentRepTool: Range metadata %d %d %d ", iStart, iEnd, iMeta); |
|
1150 |
|
1151 } |
|
1152 |
|
1153 // ----------------------------------------------------------------------------- |
|
1154 // CRangeSetting::CRangeSetting() |
|
1155 // ----------------------------------------------------------------------------- |
|
1156 // |
|
1157 |
|
1158 CRangeSetting::CRangeSetting() |
|
1159 { |
|
1160 } |
|
1161 |
|
1162 // ----------------------------------------------------------------------------- |
|
1163 // CRangeSetting::CRangeSetting() |
|
1164 // ----------------------------------------------------------------------------- |
|
1165 // |
|
1166 |
|
1167 CRangeSetting::CRangeSetting( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask) |
|
1168 : iStart( aRangeStart), iEnd( aRangeEnd), iMask( aMask) |
|
1169 { |
|
1170 if ( iMask ) |
|
1171 { |
|
1172 iType = EMaskSetting; |
|
1173 } |
|
1174 else |
|
1175 { |
|
1176 iType = ERangeSetting; |
|
1177 } |
|
1178 } |
|
1179 |
|
1180 |
|
1181 |
|
1182 // ----------------------------------------------------------------------------- |
|
1183 // CRangeSetting::NewL() |
|
1184 // ----------------------------------------------------------------------------- |
|
1185 // |
|
1186 CRangeSetting* CRangeSetting::NewL( TLex& aSecurityString) |
|
1187 { |
|
1188 CRangeSetting * setting = new (ELeave) CRangeSetting(); |
|
1189 |
|
1190 if ( KErrNone != setting->ReadRangeSetting( aSecurityString)) |
|
1191 { |
|
1192 if ( KErrNone != setting->ReadMaskSetting( aSecurityString)) |
|
1193 { |
|
1194 delete setting; |
|
1195 setting = 0; |
|
1196 } |
|
1197 } |
|
1198 |
|
1199 return setting; |
|
1200 } |
|
1201 |
|
1202 |
|
1203 // ----------------------------------------------------------------------------- |
|
1204 // CRangeSetting::Start() |
|
1205 // ----------------------------------------------------------------------------- |
|
1206 // |
|
1207 TUint32 CRangeSetting::Start() const |
|
1208 { |
|
1209 return iStart; |
|
1210 } |
|
1211 |
|
1212 // ----------------------------------------------------------------------------- |
|
1213 // CRangeSetting::End() |
|
1214 // ----------------------------------------------------------------------------- |
|
1215 // |
|
1216 TUint32 CRangeSetting::End() const |
|
1217 { |
|
1218 return iEnd; |
|
1219 } |
|
1220 |
|
1221 |
|
1222 // ----------------------------------------------------------------------------- |
|
1223 // CRangeSetting::Mask() |
|
1224 // ----------------------------------------------------------------------------- |
|
1225 // |
|
1226 TUint32 CRangeSetting::Mask() const |
|
1227 { |
|
1228 return iMask; |
|
1229 } |
|
1230 |
|
1231 |
|
1232 // ----------------------------------------------------------------------------- |
|
1233 // CRangeSetting::NewL() |
|
1234 // ----------------------------------------------------------------------------- |
|
1235 // |
|
1236 CRangeSetting* CRangeSetting::NewL( TUint32 aRangeStart, TUint32 aRangeEnd, TUint32 aMask) |
|
1237 { |
|
1238 return new (ELeave) CRangeSetting( aRangeStart, aRangeEnd, aMask); |
|
1239 } |
|
1240 |
|
1241 |
|
1242 |
|
1243 // ----------------------------------------------------------------------------- |
|
1244 // CRangeSetting::NewL() |
|
1245 // ----------------------------------------------------------------------------- |
|
1246 // |
|
1247 TInt CRangeSetting::ReadRangeSetting( TLex& aSecurityString) |
|
1248 { |
|
1249 //Read range setting, format: 0x1234 0x1234 caps |
|
1250 //set mark to start point |
|
1251 TLexMark16 mark; |
|
1252 aSecurityString.SkipSpaceAndMark( mark); |
|
1253 |
|
1254 //read next token |
|
1255 TPtrC token = aSecurityString.NextToken(); |
|
1256 |
|
1257 //shoud be a number |
|
1258 TLex firstValue( token); |
|
1259 if ( KErrNone != TIniFileHelper::ReadUNumber( iStart, firstValue ) || !firstValue.Eos()) |
|
1260 { |
|
1261 //and if not, abort evaluation and restore lex position |
|
1262 aSecurityString.UnGetToMark( mark); |
|
1263 return KErrGeneral; |
|
1264 } |
|
1265 |
|
1266 //skip spaces and get next token |
|
1267 aSecurityString.SkipSpace(); |
|
1268 token.Set( aSecurityString.NextToken()); |
|
1269 |
|
1270 //also next token should be number |
|
1271 TLex secondValue( token); |
|
1272 if ( KErrNone != TIniFileHelper::ReadUNumber( iEnd, secondValue) || !secondValue.Eos()) |
|
1273 { |
|
1274 //and if not, abort evaluation and restore lex position |
|
1275 aSecurityString.UnGetToMark( mark); |
|
1276 return KErrGeneral; |
|
1277 } |
|
1278 |
|
1279 //Ok, range setting, read caps |
|
1280 if ( KErrNone != ReadCaps( aSecurityString)) |
|
1281 { |
|
1282 //if fails, abort evaluation and restore lex position |
|
1283 aSecurityString.UnGetToMark( mark); |
|
1284 return KErrGeneral; |
|
1285 } |
|
1286 |
|
1287 return KErrNone; |
|
1288 } |
|
1289 |
|
1290 // ----------------------------------------------------------------------------- |
|
1291 // CRangeSetting::ReadMaskSetting() |
|
1292 // ----------------------------------------------------------------------------- |
|
1293 // |
|
1294 |
|
1295 TInt CRangeSetting::ReadMaskSetting( TLex& aSecurityString) |
|
1296 { |
|
1297 using namespace IniConstants; |
|
1298 //Read mask (format = 0x1234 mask=01234 caps.... |
|
1299 |
|
1300 //Skip spaces and set start mark |
|
1301 TLexMark16 mark; |
|
1302 aSecurityString.SkipSpaceAndMark( mark); |
|
1303 |
|
1304 //read first token value |
|
1305 TPtrC token = aSecurityString.NextToken(); |
|
1306 TLex value( token); |
|
1307 |
|
1308 //token should be number |
|
1309 if ( KErrNone != TIniFileHelper::ReadUNumber( iStart, value) || !value.Eos()) |
|
1310 { |
|
1311 //abort evaluation and restore lex position |
|
1312 aSecurityString.UnGetToMark( mark); |
|
1313 return KErrGeneral; |
|
1314 } |
|
1315 |
|
1316 //next token(s) should contain mask definition |
|
1317 aSecurityString.SkipSpace(); |
|
1318 token.Set( aSecurityString.NextToken()); |
|
1319 |
|
1320 //try found the mask identifier |
|
1321 TInt index = token.FindF( KMask); |
|
1322 if ( index == KErrNotFound ) |
|
1323 { |
|
1324 //and if not found, abort evaluation and restore lex position |
|
1325 aSecurityString.UnGetToMark( mark); |
|
1326 return KErrGeneral; |
|
1327 } |
|
1328 |
|
1329 //locate '='-mark, it could be part current token or in next token |
|
1330 index = token.Locate('='); |
|
1331 |
|
1332 if ( index == KErrNotFound) |
|
1333 { |
|
1334 //get next token and try locate '='-mark |
|
1335 token.Set( aSecurityString.NextToken()); |
|
1336 index = token.Locate('='); |
|
1337 |
|
1338 if ( index == KErrNotFound ) |
|
1339 { |
|
1340 //and if not found, abort evaluation and restore lex position |
|
1341 aSecurityString.UnGetToMark( mark); |
|
1342 return KErrGeneral; |
|
1343 } |
|
1344 } |
|
1345 else |
|
1346 { |
|
1347 token.Set( token.Mid(4)); |
|
1348 } |
|
1349 |
|
1350 //if token length is more than 1, it must contain also mask-value |
|
1351 if ( token.Length() > 1 ) |
|
1352 { |
|
1353 //remove '='-mark |
|
1354 token.Set( token.Mid(1)); |
|
1355 } |
|
1356 else |
|
1357 { |
|
1358 //get next token, it must contain mask-value |
|
1359 token.Set( aSecurityString.NextToken()); |
|
1360 } |
|
1361 |
|
1362 //read mask value |
|
1363 TLex maskValue( token); |
|
1364 if ( KErrNone != TIniFileHelper::ReadUNumber( iMask, maskValue) || !maskValue.Eos()) |
|
1365 { |
|
1366 //if fails, abort evaluation and restore lex position |
|
1367 aSecurityString.UnGetToMark( mark); |
|
1368 return KErrGeneral; |
|
1369 } |
|
1370 |
|
1371 //Ok, range setting, read caps |
|
1372 if ( KErrNone != ReadCaps( aSecurityString)) |
|
1373 { |
|
1374 //if fails, abort evaluation and restore lex position |
|
1375 aSecurityString.UnGetToMark( mark); |
|
1376 return KErrGeneral; |
|
1377 } |
|
1378 |
|
1379 return KErrNone; |
|
1380 } |
|
1381 |
|
1382 |
|
1383 // ----------------------------------------------------------------------------- |
|
1384 // CRangeSetting::SettingDefinition() |
|
1385 // ----------------------------------------------------------------------------- |
|
1386 // |
|
1387 |
|
1388 TDesC& CRangeSetting::SettingDefinition( TDes &aSecurityString) |
|
1389 { |
|
1390 if ( Type() == EMaskSetting ) |
|
1391 { |
|
1392 return MaskSettingDefinition( aSecurityString); |
|
1393 } |
|
1394 |
|
1395 return RangeSettingDefinition( aSecurityString); |
|
1396 } |
|
1397 |
|
1398 |
|
1399 // ----------------------------------------------------------------------------- |
|
1400 // CRangeSetting::RangeSettingDefinition() |
|
1401 // ----------------------------------------------------------------------------- |
|
1402 // |
|
1403 TDesC& CRangeSetting::RangeSettingDefinition( TDes &aSecurityString) |
|
1404 { |
|
1405 aSecurityString.Zero(); |
|
1406 |
|
1407 //create range string |
|
1408 aSecurityString.Append(_L("0x")); |
|
1409 aSecurityString.AppendNum( iStart, EHex); |
|
1410 aSecurityString.Append(' '); |
|
1411 aSecurityString.Append(_L("0x")); |
|
1412 aSecurityString.AppendNum( iEnd, EHex); |
|
1413 aSecurityString.Append(' '); |
|
1414 |
|
1415 return aSecurityString; |
|
1416 } |
|
1417 |
|
1418 |
|
1419 // ----------------------------------------------------------------------------- |
|
1420 // CRangeSetting::MaskSettingDefinition() |
|
1421 // ----------------------------------------------------------------------------- |
|
1422 // |
|
1423 TDesC& CRangeSetting::MaskSettingDefinition( TDes &aSecurityString) |
|
1424 { |
|
1425 aSecurityString.Zero(); |
|
1426 |
|
1427 //create range string |
|
1428 aSecurityString.Append(_L("0x")); |
|
1429 aSecurityString.AppendNum( iStart, EHex); |
|
1430 aSecurityString.Append(' '); |
|
1431 aSecurityString.Append( IniConstants::KMask); |
|
1432 aSecurityString.Append(_L("=0x")); |
|
1433 aSecurityString.AppendNum( iMask, EHex); |
|
1434 aSecurityString.Append(' '); |
|
1435 |
|
1436 return aSecurityString; |
|
1437 } |
|
1438 |
|
1439 |
|
1440 // ----------------------------------------------------------------------------- |
|
1441 // CRangeSetting::ExternalizeL() |
|
1442 // ----------------------------------------------------------------------------- |
|
1443 // |
|
1444 void CRangeSetting::ExternalizeL(RWriteStream& aStream) const |
|
1445 { |
|
1446 //read values |
|
1447 aStream << iStart; |
|
1448 aStream << iEnd; |
|
1449 aStream << iMask; |
|
1450 |
|
1451 //read security policies |
|
1452 CSecuritySetting::ExternalizeL( aStream); |
|
1453 |
|
1454 #ifdef _DEBUG |
|
1455 TBuf<1000> buf( KNullDesC); |
|
1456 const_cast<CRangeSetting*>(this)->SecurityString( buf); |
|
1457 |
|
1458 |
|
1459 if ( iType == ERangeSetting) |
|
1460 { |
|
1461 RDEBUG_4("CentRepTool: Range %x => %x - %S", iStart, iEnd, &buf); |
|
1462 } |
|
1463 else |
|
1464 { |
|
1465 RDEBUG_4("CentRepTool: Mask %x (mask=%x) - %S", iStart, iMask, &buf); |
|
1466 } |
|
1467 #endif |
|
1468 |
|
1469 } |
|
1470 |
|
1471 |
|
1472 // ----------------------------------------------------------------------------- |
|
1473 // CRangeSetting::InternalizeL() |
|
1474 // ----------------------------------------------------------------------------- |
|
1475 // |
|
1476 void CRangeSetting::InternalizeL(RReadStream& aStream) |
|
1477 { |
|
1478 //read values |
|
1479 aStream >> iStart; |
|
1480 aStream >> iEnd; |
|
1481 aStream >> iMask; |
|
1482 |
|
1483 if ( iEnd) |
|
1484 { |
|
1485 iType = ERangeSetting; |
|
1486 } |
|
1487 else |
|
1488 { |
|
1489 iType = EMaskSetting; |
|
1490 } |
|
1491 |
|
1492 |
|
1493 //read security policies |
|
1494 CSecuritySetting::InternalizeL( aStream); |
|
1495 |
|
1496 #ifdef _DEBUG |
|
1497 TBuf<1000> buf(KNullDesC); |
|
1498 SecurityString( buf); |
|
1499 |
|
1500 if ( iType == ERangeSetting) |
|
1501 { |
|
1502 RDEBUG_4("CentRepTool: Range %x => %x - %S", iStart, iEnd, &buf); |
|
1503 } |
|
1504 else |
|
1505 { |
|
1506 RDEBUG_4("CentRepTool: Mask %x (mask=%x) - %S", iStart, iMask, &buf); |
|
1507 } |
|
1508 #endif |
|
1509 } |
|
1510 |
|
1511 |
|
1512 |
|
1513 |
|
1514 |
|
1515 |
|
1516 // ----------------------------------------------------------------------------- |
|
1517 // CDefaultSetting::CDefaultSetting() |
|
1518 // ----------------------------------------------------------------------------- |
|
1519 // |
|
1520 CDefaultSetting::CDefaultSetting() |
|
1521 { |
|
1522 |
|
1523 } |
|
1524 |
|
1525 |
|
1526 // ----------------------------------------------------------------------------- |
|
1527 // CDefaultSetting::NewL() |
|
1528 // ----------------------------------------------------------------------------- |
|
1529 // |
|
1530 |
|
1531 CDefaultSetting* CDefaultSetting::NewL( TLex& aSecurityString) |
|
1532 { |
|
1533 CDefaultSetting * setting = new (ELeave) CDefaultSetting(); |
|
1534 |
|
1535 if ( KErrNone != setting->ReadSetting( aSecurityString)) |
|
1536 { |
|
1537 delete setting; |
|
1538 setting = 0; |
|
1539 } |
|
1540 |
|
1541 return setting; |
|
1542 } |
|
1543 |
|
1544 |
|
1545 // ----------------------------------------------------------------------------- |
|
1546 // CDefaultSetting::ReadSetting() |
|
1547 // ----------------------------------------------------------------------------- |
|
1548 // |
|
1549 |
|
1550 TInt CDefaultSetting::ReadSetting( TLex& aSecurityString) |
|
1551 { |
|
1552 //No setting specific part -> read caps |
|
1553 TLexMark16 mark; |
|
1554 aSecurityString.Mark( mark); |
|
1555 |
|
1556 if ( KErrNone != ReadCaps( aSecurityString)) |
|
1557 { |
|
1558 aSecurityString.UnGetToMark( mark); |
|
1559 return KErrGeneral; |
|
1560 } |
|
1561 |
|
1562 return KErrNone; |
|
1563 } |
|
1564 |
|
1565 // ----------------------------------------------------------------------------- |
|
1566 // CDefaultSetting::NewL() |
|
1567 // ----------------------------------------------------------------------------- |
|
1568 // |
|
1569 |
|
1570 |
|
1571 TDesC& CDefaultSetting::SettingDefinition( TDes &aSecurityString) |
|
1572 { |
|
1573 aSecurityString = KNullDesC; |
|
1574 return aSecurityString; |
|
1575 } |
|
1576 |
|
1577 // ----------------------------------------------------------------------------- |
|
1578 // CDefaultSetting::ExternalizeL() |
|
1579 // ----------------------------------------------------------------------------- |
|
1580 // |
|
1581 void CDefaultSetting::ExternalizeL(RWriteStream& aStream) const |
|
1582 { |
|
1583 CSecuritySetting::ExternalizeL( aStream); |
|
1584 |
|
1585 } |
|
1586 |
|
1587 // ----------------------------------------------------------------------------- |
|
1588 // CDefaultSetting::InternalizeL() |
|
1589 // ----------------------------------------------------------------------------- |
|
1590 // |
|
1591 void CDefaultSetting::InternalizeL(RReadStream& aStream) |
|
1592 { |
|
1593 CSecuritySetting::InternalizeL( aStream); |
|
1594 |
|
1595 #ifdef _DEBUG |
|
1596 TBuf<500> buf( KNullDesC); |
|
1597 SecurityString( buf); |
|
1598 RDEBUG_2("CentRepTool: Security policy %S", &buf); |
|
1599 #endif |
|
1600 } |
|
1601 |
|
1602 |
|
1603 // ----------------------------------------------------------------------------- |
|
1604 // CIndividualSetting::CIndividualSetting() |
|
1605 // ----------------------------------------------------------------------------- |
|
1606 // |
|
1607 CIndividualSetting::CIndividualSetting() |
|
1608 : CSecuritySetting() |
|
1609 { |
|
1610 |
|
1611 } |
|
1612 |
|
1613 |
|
1614 // ----------------------------------------------------------------------------- |
|
1615 // CIndividualSetting::CIndividualSetting() |
|
1616 // ----------------------------------------------------------------------------- |
|
1617 // |
|
1618 CIndividualSetting::CIndividualSetting( const TUint32& aSettingId) |
|
1619 : CSecuritySetting(), iSettingId( aSettingId) |
|
1620 { |
|
1621 |
|
1622 } |
|
1623 |
|
1624 |
|
1625 // ----------------------------------------------------------------------------- |
|
1626 // CIndividualSetting::~CIndividualSetting() |
|
1627 // ----------------------------------------------------------------------------- |
|
1628 // |
|
1629 CIndividualSetting::~CIndividualSetting() |
|
1630 { |
|
1631 if ( iSettingType == EString) |
|
1632 { |
|
1633 delete iSettingValue.iStringValue; |
|
1634 } |
|
1635 } |
|
1636 |
|
1637 |
|
1638 // ----------------------------------------------------------------------------- |
|
1639 // CIndividualSetting::NewL() |
|
1640 // ----------------------------------------------------------------------------- |
|
1641 // |
|
1642 |
|
1643 CIndividualSetting* CIndividualSetting::NewL( TLex& aSecurityString) |
|
1644 { |
|
1645 //Create setting |
|
1646 CIndividualSetting * setting = new (ELeave) CIndividualSetting(); |
|
1647 CleanupStack::PushL( setting); |
|
1648 |
|
1649 //read individual setting info |
|
1650 setting->ReadSettingL( aSecurityString); |
|
1651 |
|
1652 CleanupStack::Pop( setting); |
|
1653 |
|
1654 //return created object |
|
1655 return setting; |
|
1656 } |
|
1657 |
|
1658 |
|
1659 |
|
1660 |
|
1661 |
|
1662 // ----------------------------------------------------------------------------- |
|
1663 // CIndividualSetting::ReadSetting() |
|
1664 // ----------------------------------------------------------------------------- |
|
1665 // |
|
1666 void CIndividualSetting::ReadSettingL( TLex& aSecurityString) |
|
1667 { |
|
1668 //Mark original point |
|
1669 iData.Set( aSecurityString.Remainder()); |
|
1670 |
|
1671 //Read tokens,,, |
|
1672 TLex idLex( aSecurityString.NextToken()); //id |
|
1673 |
|
1674 if ( KErrNone != TIniFileHelper::ReadUNumber( iSettingId, idLex)) |
|
1675 { |
|
1676 User::Leave( KErrCorrupt); |
|
1677 } |
|
1678 |
|
1679 TPtrC type = aSecurityString.NextToken(); //type |
|
1680 |
|
1681 //read settings type |
|
1682 if ( type.CompareF( IniConstants::KTypeInt ) == 0) |
|
1683 { |
|
1684 iSettingType = EInt; |
|
1685 } |
|
1686 else if ( type.CompareF( IniConstants::KTypeReal ) == 0) |
|
1687 { |
|
1688 iSettingType = EReal; |
|
1689 } |
|
1690 else if ( type.CompareF( IniConstants::KTypeString ) == 0 ) |
|
1691 { |
|
1692 iSettingType = EString; |
|
1693 } |
|
1694 else if ( type.CompareF( IniConstants::KTypeString8 ) == 0 ) |
|
1695 { |
|
1696 iSettingType = EString8; |
|
1697 } |
|
1698 else if ( type.CompareF( IniConstants::KTypeBinary ) == 0) |
|
1699 { |
|
1700 iSettingType = EBinaryType; |
|
1701 } |
|
1702 else |
|
1703 { |
|
1704 User::Leave( KErrCorrupt); |
|
1705 } |
|
1706 |
|
1707 |
|
1708 TInt err = KErrNone; |
|
1709 aSecurityString.SkipSpace(); |
|
1710 |
|
1711 |
|
1712 //read setting value |
|
1713 switch ( iSettingType) |
|
1714 { |
|
1715 case EInt : |
|
1716 { |
|
1717 TLex valueLex( aSecurityString.NextToken()); |
|
1718 TInt32 value; |
|
1719 err = TIniFileHelper::ReadNumber( value, valueLex); |
|
1720 iSettingValue.iIntegerValue = value; |
|
1721 } |
|
1722 break; |
|
1723 case EReal : |
|
1724 { |
|
1725 TLex valueLex( aSecurityString.NextToken()); |
|
1726 err = TIniFileHelper::ReadNumber( iSettingValue.iRealValue, valueLex); |
|
1727 } |
|
1728 break; |
|
1729 case EString: |
|
1730 { |
|
1731 err = TIniFileHelper::StringReadL( aSecurityString, iSettingValue.iStringValue); |
|
1732 } |
|
1733 break; |
|
1734 case EString8: |
|
1735 { |
|
1736 err = TIniFileHelper::String8ReadL( aSecurityString, iSettingValue.iStringValue); |
|
1737 iSettingType = EString; |
|
1738 } |
|
1739 break; |
|
1740 case EBinaryType: |
|
1741 { |
|
1742 err = TIniFileHelper::BinaryReadL( aSecurityString, iSettingValue.iStringValue); |
|
1743 iSettingType = EString; |
|
1744 } |
|
1745 break; |
|
1746 default: |
|
1747 //not possible case.... |
|
1748 break; |
|
1749 } |
|
1750 |
|
1751 if ( err != KErrNone) |
|
1752 { |
|
1753 User::Leave( KErrCorrupt); |
|
1754 } |
|
1755 |
|
1756 //Meta data |
|
1757 TLex lexMeta( aSecurityString.NextToken()); |
|
1758 err = TIniFileHelper::ReadUNumber( iMeta, lexMeta); |
|
1759 // if no metadata found -> will return KErrGeneral |
|
1760 if( err == KErrGeneral ) |
|
1761 { |
|
1762 iMeta = 0; |
|
1763 } |
|
1764 else |
|
1765 { |
|
1766 User::LeaveIfError( err ); // will leave if KErrOverflow, otherwise won't leave |
|
1767 } |
|
1768 |
|
1769 //set iData to point data area of setting |
|
1770 iData.Set( iData.Left( aSecurityString.Offset())); |
|
1771 |
|
1772 //Ok, read caps |
|
1773 if ( KErrNone != ReadCaps( aSecurityString)) |
|
1774 { |
|
1775 User::Leave( KErrCorrupt); |
|
1776 } |
|
1777 } |
|
1778 |
|
1779 // ----------------------------------------------------------------------------- |
|
1780 // CIndividualSetting::SettingDefinition() |
|
1781 // ----------------------------------------------------------------------------- |
|
1782 // |
|
1783 |
|
1784 TDesC& CIndividualSetting::SettingDefinition( TDes& /*aSecurityString*/) |
|
1785 { |
|
1786 return iData; |
|
1787 } |
|
1788 |
|
1789 |
|
1790 |
|
1791 // ----------------------------------------------------------------------------- |
|
1792 // CIndividualSetting::ExternalizeL() |
|
1793 // ----------------------------------------------------------------------------- |
|
1794 // |
|
1795 void CIndividualSetting::ExternalizeDataL(RWriteStream& aStream) const |
|
1796 { |
|
1797 //set setting id and meta data value |
|
1798 aStream << iSettingId; |
|
1799 aStream << iMeta; |
|
1800 |
|
1801 //setting type |
|
1802 TUint8 temp = static_cast<TUint8>(iSettingType); |
|
1803 aStream << temp; |
|
1804 |
|
1805 #ifdef _DEBUG |
|
1806 //buffer for security string |
|
1807 TBuf<500> buf( KNullDesC); |
|
1808 const_cast<CIndividualSetting*>(this)->SecurityString( buf); |
|
1809 #endif |
|
1810 |
|
1811 //write value |
|
1812 switch ( iSettingType) |
|
1813 { |
|
1814 case EInt: |
|
1815 { |
|
1816 TInt32 value = iSettingValue.iIntegerValue; |
|
1817 aStream << value; |
|
1818 //RDEBUG_4("CentRepTool: Int meta: %u value: %u - %S", iMeta, value, &buf); |
|
1819 } |
|
1820 break; |
|
1821 case EReal: |
|
1822 { |
|
1823 aStream << iSettingValue.iRealValue; |
|
1824 //RDEBUG_4("CentRepTool: Real meta: %u value: %e - %S", iMeta, iSettingValue.iRealValue, &buf); |
|
1825 } |
|
1826 break; |
|
1827 case EString : |
|
1828 { |
|
1829 aStream << *(iSettingValue.iStringValue); |
|
1830 //RDEBUG_4("CentRepTool: String meta: %u value: %S - %S", iMeta, iSettingValue.iStringValue, &buf); |
|
1831 } |
|
1832 break ; |
|
1833 default: |
|
1834 break; |
|
1835 } |
|
1836 } |
|
1837 |
|
1838 // ----------------------------------------------------------------------------- |
|
1839 // CIndividualSetting::InternalizeL() |
|
1840 // ----------------------------------------------------------------------------- |
|
1841 // |
|
1842 void CIndividualSetting::InternalizeDataL(RReadStream& aStream) |
|
1843 { |
|
1844 //get setting meta data value |
|
1845 aStream >> iMeta; |
|
1846 |
|
1847 //read setting type |
|
1848 TUint8 temp; |
|
1849 aStream >> temp; |
|
1850 iSettingType = static_cast<TSettingType>(temp); |
|
1851 |
|
1852 #ifdef _DEBUG |
|
1853 //buffer for security string |
|
1854 TBuf<500> buf( KNullDesC); |
|
1855 SecurityString( buf); |
|
1856 #endif |
|
1857 |
|
1858 //read value |
|
1859 switch ( iSettingType) |
|
1860 { |
|
1861 case EInt: |
|
1862 { |
|
1863 TInt32 value; |
|
1864 aStream >> value ; |
|
1865 iSettingValue.iIntegerValue =value; |
|
1866 //RDEBUG_4("CentRepTool: Int: meta: %u value: %d - %S", iMeta, value, &buf); |
|
1867 } |
|
1868 break; |
|
1869 case EReal: |
|
1870 { |
|
1871 aStream >> iSettingValue.iRealValue; |
|
1872 //RDEBUG_4("CentRepTool: Real: meta: %u value %e - %S", iMeta, iSettingValue.iRealValue, &buf); |
|
1873 } |
|
1874 break; |
|
1875 case EString : |
|
1876 { |
|
1877 iSettingValue.iStringValue = HBufC8::NewL ( aStream, NCentralRepositoryConstants::KMaxBinaryLength); |
|
1878 //RDEBUG_4("CentRepTool: String: meta: %u value %S - %S", iMeta, iSettingValue.iStringValue, &buf); |
|
1879 } |
|
1880 break ; |
|
1881 default: |
|
1882 break; |
|
1883 } |
|
1884 |
|
1885 } |
|
1886 |
|
1887 // ----------------------------------------------------------------------------- |
|
1888 // CIndividualSetting::ExternalizePlatSecL() |
|
1889 // ----------------------------------------------------------------------------- |
|
1890 // |
|
1891 void CIndividualSetting::ExternalizePlatSecL(RWriteStream& aStream) const |
|
1892 { |
|
1893 TUint32 dummyValue(0); |
|
1894 |
|
1895 aStream << iSettingId; |
|
1896 aStream << dummyValue; |
|
1897 aStream << dummyValue; |
|
1898 |
|
1899 CSecuritySetting::ExternalizeL( aStream); |
|
1900 } |
|
1901 |
|
1902 |
|
1903 // ----------------------------------------------------------------------------- |
|
1904 // CIndividualSetting::InternalizePlatSecL() |
|
1905 // ----------------------------------------------------------------------------- |
|
1906 // |
|
1907 void CIndividualSetting::InternalizePlatSecL(RReadStream& aStream) |
|
1908 { |
|
1909 TUint32 dummyValue(0); |
|
1910 |
|
1911 aStream >> iSettingId; |
|
1912 aStream >> dummyValue; |
|
1913 aStream >> dummyValue; |
|
1914 |
|
1915 CSecuritySetting::InternalizeL( aStream); |
|
1916 } |
|
1917 |
|
1918 // ----------------------------------------------------------------------------- |
|
1919 // CIndividualSetting::CompareElements() |
|
1920 // ----------------------------------------------------------------------------- |
|
1921 // |
|
1922 TInt CIndividualSetting::CompareElements( CIndividualSetting const& aSetting1, CIndividualSetting const& aSetting2) |
|
1923 { |
|
1924 if ( aSetting1.iSettingId == aSetting2.iSettingId) return 0; |
|
1925 return ( aSetting1.iSettingId < aSetting2.iSettingId ? -1 : 1 ); |
|
1926 } |
|
1927 |
|
1928 |
|
1929 // ----------------------------------------------------------------------------- |
|
1930 // TIniFileHelper::ReadNumber() |
|
1931 // ----------------------------------------------------------------------------- |
|
1932 // |
|
1933 |
|
1934 TInt TIniFileHelper::ReadNumber( TInt32& aNumber, TLex& aLex) |
|
1935 { |
|
1936 return aLex.Val( aNumber); |
|
1937 } |
|
1938 |
|
1939 |
|
1940 // ----------------------------------------------------------------------------- |
|
1941 // TIniFileHelper::ReadUNumber() |
|
1942 // ----------------------------------------------------------------------------- |
|
1943 // |
|
1944 |
|
1945 TInt TIniFileHelper::ReadUNumber( TUint32& aNumber, TLex& aLex) |
|
1946 { |
|
1947 TRadix radix = EDecimal; |
|
1948 |
|
1949 if( aLex.Peek()=='0') |
|
1950 { |
|
1951 aLex.Inc(); |
|
1952 if( aLex.Peek().GetLowerCase()=='x') |
|
1953 { |
|
1954 aLex.Inc(); |
|
1955 radix = EHex; |
|
1956 } |
|
1957 else |
|
1958 { |
|
1959 aLex.UnGet(); |
|
1960 } |
|
1961 } |
|
1962 |
|
1963 return aLex.Val( aNumber, radix); |
|
1964 } |
|
1965 |
|
1966 |
|
1967 // ----------------------------------------------------------------------------- |
|
1968 // TIniFileHelper::ReadNumber() |
|
1969 // ----------------------------------------------------------------------------- |
|
1970 // |
|
1971 |
|
1972 TInt TIniFileHelper::ReadNumber( TReal& aNumber, TLex& aLex) |
|
1973 { |
|
1974 return aLex.Val( aNumber); |
|
1975 } |
|
1976 |
|
1977 // ----------------------------------------------------------------------------- |
|
1978 // TIniFileHelper::TIniFileHelper() |
|
1979 // ----------------------------------------------------------------------------- |
|
1980 // |
|
1981 |
|
1982 TIniFileHelper::TIniFileHelper() |
|
1983 { |
|
1984 } |
|
1985 |
|
1986 |
|
1987 // ----------------------------------------------------------------------------- |
|
1988 // TIniFileHelper::ReadFileL() |
|
1989 // ----------------------------------------------------------------------------- |
|
1990 // |
|
1991 |
|
1992 HBufC* TIniFileHelper::ReadFileL(RFile& aFile) |
|
1993 { |
|
1994 TInt size; |
|
1995 |
|
1996 //seek to start of the file |
|
1997 TInt seekOffset(0); |
|
1998 aFile.Seek( ESeekStart, seekOffset); |
|
1999 |
|
2000 User::LeaveIfError( aFile.Size(size)); |
|
2001 |
|
2002 if(size<4) |
|
2003 { |
|
2004 User::Leave(KErrCorrupt); |
|
2005 } |
|
2006 |
|
2007 TInt len = size/2-1; |
|
2008 |
|
2009 HBufC16* buf = HBufC16::NewL(len); |
|
2010 |
|
2011 TPtr16 ptr16 = buf->Des(); |
|
2012 TPtr8 ptr8( (TUint8*)ptr16.Ptr(), 0, 2); |
|
2013 |
|
2014 User::LeaveIfError(aFile.Read( ptr8, 2)); |
|
2015 |
|
2016 |
|
2017 if( *ptr16.Ptr() != IniConstants::KUcs2Bom) |
|
2018 { |
|
2019 User::Leave(KErrCorrupt); |
|
2020 } |
|
2021 |
|
2022 ptr8.Set((TUint8*)ptr16.Ptr(), 0, size-2); |
|
2023 User::LeaveIfError(aFile.Read(ptr8)); |
|
2024 ptr16.SetLength(len); |
|
2025 |
|
2026 return buf; |
|
2027 } |
|
2028 |
|
2029 |
|
2030 |
|
2031 // ----------------------------------------------------------------------------- |
|
2032 // TIniFileHelper::StartWriteL() |
|
2033 // ----------------------------------------------------------------------------- |
|
2034 // |
|
2035 |
|
2036 TInt TIniFileHelper::StartWrite( RFile& aFile) |
|
2037 { |
|
2038 iFile = &aFile; |
|
2039 iSize = 0; |
|
2040 |
|
2041 TBuf<1> buf; |
|
2042 buf.Append( IniConstants::KUcs2Bom); |
|
2043 |
|
2044 TPtrC8 ptr8Ucs2Bom((TUint8*)buf.Ptr(), buf.Length()*2); |
|
2045 |
|
2046 //In debug builds debug file is created, file is used in testing |
|
2047 #ifdef _DEBUG |
|
2048 _LIT( KCentRepTestFile, "C:\\centreptestfile.txt"); |
|
2049 |
|
2050 TInt e = iDebugFs.Connect(); |
|
2051 if( e != KErrNone ) |
|
2052 { |
|
2053 return e; |
|
2054 } |
|
2055 |
|
2056 TInt err = iDebugFile.Open( iDebugFs, KCentRepTestFile, EFileWrite); |
|
2057 if ( err == KErrNotFound ) |
|
2058 { |
|
2059 err = iDebugFile.Create( iDebugFs, KCentRepTestFile, EFileWrite); |
|
2060 } |
|
2061 |
|
2062 iDebugFile.Write( 0, ptr8Ucs2Bom); |
|
2063 |
|
2064 #endif //_DEBUG |
|
2065 |
|
2066 return aFile.Write( 0, ptr8Ucs2Bom); |
|
2067 } |
|
2068 |
|
2069 // ----------------------------------------------------------------------------- |
|
2070 // TIniFileHelper::WriteToFileL() |
|
2071 // ----------------------------------------------------------------------------- |
|
2072 // |
|
2073 TInt TIniFileHelper::WriteToFile( const TDesC& aContent) |
|
2074 { |
|
2075 |
|
2076 TPtrC content = aContent; |
|
2077 iSize += content.Length() * 2; |
|
2078 |
|
2079 TPtrC8 ptr8((TUint8*)content.Ptr(), content.Length()*2); |
|
2080 |
|
2081 #ifdef _DEBUG |
|
2082 iDebugFile.Write( ptr8); |
|
2083 #endif //_DEBUG |
|
2084 |
|
2085 return iFile->Write( ptr8); |
|
2086 } |
|
2087 |
|
2088 // ----------------------------------------------------------------------------- |
|
2089 // TIniFileHelper::LineFeed() |
|
2090 // ----------------------------------------------------------------------------- |
|
2091 // |
|
2092 TInt TIniFileHelper::LineFeed() |
|
2093 { |
|
2094 TBuf<2> buf; |
|
2095 buf.Append( 0x0d); |
|
2096 buf.Append( 0x0a); |
|
2097 |
|
2098 return WriteToFile(buf); |
|
2099 } |
|
2100 |
|
2101 // ----------------------------------------------------------------------------- |
|
2102 // TIniFileHelper::FinishWrite() |
|
2103 // ----------------------------------------------------------------------------- |
|
2104 // |
|
2105 TInt TIniFileHelper::FinishWrite() |
|
2106 { |
|
2107 TInt err = iFile->SetSize( iSize + 2); |
|
2108 |
|
2109 if ( err == KErrNone ) |
|
2110 { |
|
2111 err = iFile->Flush(); |
|
2112 } |
|
2113 |
|
2114 #ifdef _DEBUG |
|
2115 iDebugFile.SetSize( iSize + 2); |
|
2116 iDebugFile.Flush(); |
|
2117 |
|
2118 iDebugFile.Close(); |
|
2119 iDebugFs.Close(); |
|
2120 #endif //_DEBUG |
|
2121 |
|
2122 |
|
2123 return err; |
|
2124 } |
|
2125 |
|
2126 // ----------------------------------------------------------------------------- |
|
2127 // TIniFileHelper::NextLine() |
|
2128 // ----------------------------------------------------------------------------- |
|
2129 |
|
2130 void TIniFileHelper::NextLine( TPtrC& aContent, TPtrC& aNextLine) |
|
2131 { |
|
2132 if ( aContent.Length()) |
|
2133 { |
|
2134 //remove extra marks from begin of line |
|
2135 while ( aContent[0] == 10 || aContent[0] == 13 || aContent[0] == ' ') |
|
2136 { |
|
2137 aContent.Set( aContent.Mid( 1)); |
|
2138 |
|
2139 if ( !aContent.Length()) |
|
2140 { |
|
2141 break; |
|
2142 } |
|
2143 } |
|
2144 |
|
2145 //get a next line and remove comment lines |
|
2146 do |
|
2147 { |
|
2148 TInt index = aContent.Locate( 10); |
|
2149 if ( index != KErrNotFound) |
|
2150 { |
|
2151 aNextLine.Set( aContent.Left( index)); |
|
2152 aContent.Set( aContent.Mid( index + 1)); |
|
2153 } |
|
2154 else |
|
2155 { |
|
2156 aNextLine.Set( aContent); |
|
2157 aContent.Set( KNullDesC); |
|
2158 break; |
|
2159 } |
|
2160 |
|
2161 if ( !aNextLine.Length()) |
|
2162 { |
|
2163 break; |
|
2164 } |
|
2165 } while ( aNextLine[0] == '#'); |
|
2166 |
|
2167 |
|
2168 //remove extra mark from end of string |
|
2169 while ( aNextLine.Length() && aNextLine [aNextLine.Length() - 1] == 13) |
|
2170 { |
|
2171 aNextLine.Set( aNextLine.Left( aNextLine.Length() - 1)); |
|
2172 } |
|
2173 }; |
|
2174 } |
|
2175 |
|
2176 // ----------------------------------------------------------------------------- |
|
2177 // TIniFileHelper::CompareElements() |
|
2178 // ----------------------------------------------------------------------------- |
|
2179 |
|
2180 TInt TIniFileHelper::CompareElements( CRangeSetting const& aElement1, CRangeSetting const& aElement2) |
|
2181 { |
|
2182 if ( aElement1.Start() == aElement2.Start()) return 0; |
|
2183 return ( aElement1.Start() < aElement2.Start() ? -1 : 1 ); |
|
2184 } |
|
2185 |
|
2186 |
|
2187 // ----------------------------------------------------------------------------- |
|
2188 // TIniFileHelper::CompareElements() |
|
2189 // ----------------------------------------------------------------------------- |
|
2190 |
|
2191 TInt TIniFileHelper::CompareElements( CRangeMeta const& aElement1, CRangeMeta const& aElement2) |
|
2192 { |
|
2193 if ( aElement1.Start() == aElement2.Start()) return 0; |
|
2194 return ( aElement1.Start() < aElement2.Start() ? -1 : 1 ); |
|
2195 } |
|
2196 |
|
2197 // ----------------------------------------------------------------------------- |
|
2198 // TIniFileHelper::ReadStringL() |
|
2199 // ----------------------------------------------------------------------------- |
|
2200 |
|
2201 TInt TIniFileHelper::StringReadL( TLex& aLex, HBufC8*& aString) |
|
2202 { |
|
2203 aLex.Mark(); |
|
2204 |
|
2205 //locate ' or " |
|
2206 TChar c( aLex.Peek()); |
|
2207 TChar quote ( 0); |
|
2208 if(c=='\'' || c=='\"') |
|
2209 { |
|
2210 aLex.SkipAndMark(1); |
|
2211 quote = c; |
|
2212 } |
|
2213 |
|
2214 TBool complete( EFalse); |
|
2215 |
|
2216 TInt len(0); |
|
2217 for(len=0;!aLex.Eos();len++) |
|
2218 { |
|
2219 c = aLex.Get(); |
|
2220 |
|
2221 |
|
2222 if( quote ? c==quote : c.IsSpace() || aLex.Eos() ) |
|
2223 { |
|
2224 complete = ETrue; |
|
2225 break; |
|
2226 } |
|
2227 |
|
2228 if(c=='\\') |
|
2229 { |
|
2230 aLex.Get(); |
|
2231 } |
|
2232 } |
|
2233 |
|
2234 if(!complete || len> NCentralRepositoryConstants::KMaxUnicodeStringLength) |
|
2235 { |
|
2236 return KErrCorrupt; |
|
2237 } |
|
2238 |
|
2239 aString = HBufC8::NewL(len*2); |
|
2240 TPtr8 ptr8 = aString->Des(); |
|
2241 ptr8.SetLength(len*2); |
|
2242 TPtr16 ptr16((TUint16*)ptr8.Ptr(), len, len); |
|
2243 |
|
2244 aLex.UnGetToMark(); |
|
2245 |
|
2246 _LIT(KSpecialChars, "abfnrvt0"); |
|
2247 static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; |
|
2248 for(TInt i=0;i<len;i++) |
|
2249 { |
|
2250 c = aLex.Get(); |
|
2251 |
|
2252 if(c=='\\') |
|
2253 { |
|
2254 c = aLex.Get(); |
|
2255 TInt i = KSpecialChars().Locate(c); |
|
2256 if(i>=0) |
|
2257 c = specialChars[i]; |
|
2258 } |
|
2259 ptr16[i] = (TUint16)c; |
|
2260 } |
|
2261 |
|
2262 if(quote) |
|
2263 { |
|
2264 aLex.Inc(); |
|
2265 } |
|
2266 |
|
2267 return KErrNone; |
|
2268 } |
|
2269 |
|
2270 |
|
2271 // ----------------------------------------------------------------------------- |
|
2272 // TIniFileHelper::ReadString8L() |
|
2273 // ----------------------------------------------------------------------------- |
|
2274 TInt TIniFileHelper::String8ReadL( TLex& aLex, HBufC8*& aString) |
|
2275 { |
|
2276 aLex.Mark(); |
|
2277 |
|
2278 TChar c( aLex.Peek()); |
|
2279 TChar quote( 0); |
|
2280 if( c=='\'' || c=='\"') |
|
2281 { |
|
2282 aLex.SkipAndMark(1); |
|
2283 quote = c; |
|
2284 } |
|
2285 |
|
2286 TBool complete( EFalse); |
|
2287 |
|
2288 TInt len(0); |
|
2289 for(len=0;!aLex.Eos();len++) |
|
2290 { |
|
2291 c = aLex.Get(); |
|
2292 |
|
2293 if(quote ? c==quote : c.IsSpace()) |
|
2294 { |
|
2295 complete = ETrue; |
|
2296 break; |
|
2297 } |
|
2298 |
|
2299 if(c=='\\') |
|
2300 { |
|
2301 aLex.Get(); |
|
2302 } |
|
2303 } |
|
2304 |
|
2305 if(!complete || len> NCentralRepositoryConstants::KMaxUnicodeStringLength) |
|
2306 { |
|
2307 return KErrCorrupt; |
|
2308 } |
|
2309 |
|
2310 aString = HBufC8::NewLC(len*2); |
|
2311 |
|
2312 HBufC16* tempBuffer = HBufC16::NewLC(len); |
|
2313 |
|
2314 TPtr16 ptr16 = tempBuffer->Des(); |
|
2315 TPtr8 ptr8 = aString->Des(); |
|
2316 ptr8.SetLength(len*2); |
|
2317 |
|
2318 aLex.UnGetToMark(); |
|
2319 |
|
2320 _LIT(KSpecialChars, "abfnrvt0"); |
|
2321 static TUint8 specialChars[] = { '\a', '\b', '\f', '\n', '\r', '\v', '\t', '\0' }; |
|
2322 for(TInt i=0;i<len;i++) |
|
2323 { |
|
2324 c = aLex.Get(); |
|
2325 |
|
2326 if ( c=='\\') |
|
2327 { |
|
2328 c = aLex.Get(); |
|
2329 TInt i = KSpecialChars().Locate(c); |
|
2330 if(i>=0) |
|
2331 c = specialChars[i]; |
|
2332 } |
|
2333 |
|
2334 ptr16.Append(c); |
|
2335 |
|
2336 } |
|
2337 |
|
2338 const TInt returnValue = CnvUtfConverter::ConvertFromUnicodeToUtf8(ptr8, ptr16); |
|
2339 if (returnValue==CnvUtfConverter::EErrorIllFormedInput) |
|
2340 { |
|
2341 CleanupStack::PopAndDestroy(tempBuffer); |
|
2342 CleanupStack::PopAndDestroy(aString); |
|
2343 return KErrCorrupt; |
|
2344 } |
|
2345 else if(returnValue<0) |
|
2346 { |
|
2347 User::Leave(KErrGeneral); |
|
2348 } |
|
2349 |
|
2350 CleanupStack::PopAndDestroy(tempBuffer); |
|
2351 CleanupStack::Pop(aString); |
|
2352 |
|
2353 if(quote) |
|
2354 { |
|
2355 aLex.Inc(); |
|
2356 } |
|
2357 |
|
2358 return KErrNone; |
|
2359 } |
|
2360 |
|
2361 // ----------------------------------------------------------------------------- |
|
2362 // TIniFileHelper::ReadBinaryL() |
|
2363 // ----------------------------------------------------------------------------- |
|
2364 TInt TIniFileHelper::BinaryReadL( TLex& aLex, HBufC8*& aString) |
|
2365 { |
|
2366 aLex.Mark(); |
|
2367 aLex.SkipCharacters(); |
|
2368 TInt len( aLex.TokenLength()); |
|
2369 aLex.UnGetToMark(); |
|
2370 |
|
2371 if(len==1 && aLex.Peek() == KNullDataIndicator) |
|
2372 { |
|
2373 aLex.Get(); |
|
2374 aString = HBufC8::NewL(0); |
|
2375 TPtr8 ptr8 = aString->Des(); |
|
2376 ptr8.SetLength(0); |
|
2377 return KErrNone; |
|
2378 } |
|
2379 |
|
2380 if( len> NCentralRepositoryConstants::KMaxBinaryLength*2 || len%2) |
|
2381 { |
|
2382 delete aString; |
|
2383 return KErrCorrupt; |
|
2384 } |
|
2385 |
|
2386 len /= 2; |
|
2387 aString = HBufC8::NewL(len); |
|
2388 TPtr8 ptr8 = aString->Des(); |
|
2389 ptr8.SetLength(len); |
|
2390 |
|
2391 TBuf<2> buf(2); |
|
2392 for(TInt i=0;i<len;i++) |
|
2393 { |
|
2394 buf[0] = (TUint8)aLex.Get(); |
|
2395 buf[1] = (TUint8)aLex.Get(); |
|
2396 TLex lex(buf); |
|
2397 if(lex.Val(ptr8[i], EHex)!=KErrNone) |
|
2398 { |
|
2399 delete aString; |
|
2400 return KErrCorrupt; |
|
2401 } |
|
2402 } |
|
2403 return KErrNone; |
|
2404 } |