|
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 #include "elements.h" |
|
22 #include "PolicyParser.h" |
|
23 #include "XACMLconstants.h" |
|
24 #include "DataTypes.h" |
|
25 #include "PolicyProcessor.h" |
|
26 #include "PolicyStorage.h" |
|
27 #include "ErrorCodes.h" |
|
28 #include "debug.h" |
|
29 |
|
30 |
|
31 |
|
32 // ----------------------------------------------------------------------------- |
|
33 // RContentBuilder::RContentBuilder() |
|
34 // ----------------------------------------------------------------------------- |
|
35 // |
|
36 |
|
37 RContentBuilder::RContentBuilder() |
|
38 : RPointerArray<HBufC8>(), iSize(0) |
|
39 { |
|
40 } |
|
41 |
|
42 // ----------------------------------------------------------------------------- |
|
43 // RContentBuilder::AddContentL() |
|
44 // ----------------------------------------------------------------------------- |
|
45 // |
|
46 |
|
47 void RContentBuilder::AddContentL( HBufC8 * aBuffer) |
|
48 { |
|
49 //Append buffer to pointer array |
|
50 CleanupStack::PushL( aBuffer); |
|
51 User::LeaveIfError( Append( aBuffer)); |
|
52 CleanupStack::Pop( aBuffer); |
|
53 |
|
54 //calculate new total size |
|
55 iSize += aBuffer->Length(); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // RContentBuilder::ContentL() |
|
60 // ----------------------------------------------------------------------------- |
|
61 // |
|
62 |
|
63 HBufC8 * RContentBuilder::ContentL() |
|
64 { |
|
65 //create buffer for new content |
|
66 HBufC8 * buffer = HBufC8::NewL( iSize); |
|
67 TPtr8 ptr = buffer->Des(); |
|
68 |
|
69 //and append content of pointer array to buffer (step by step) |
|
70 for ( TInt i(0); i < Count(); i++) |
|
71 { |
|
72 ptr.Append( *operator[]( i)); |
|
73 } |
|
74 |
|
75 //return buffer |
|
76 return buffer; |
|
77 } |
|
78 |
|
79 // ----------------------------------------------------------------------------- |
|
80 // RContentBuilder::ContentLC() |
|
81 // ----------------------------------------------------------------------------- |
|
82 // |
|
83 |
|
84 HBufC8 * RContentBuilder::ContentLC() |
|
85 { |
|
86 //create buffer and push it to cleanupstack |
|
87 HBufC8 * buffer = ContentL(); |
|
88 CleanupStack::PushL( buffer); |
|
89 |
|
90 //return buffer |
|
91 return buffer; |
|
92 } |
|
93 |
|
94 // ----------------------------------------------------------------------------- |
|
95 // RContentBuilder::Close() |
|
96 // ----------------------------------------------------------------------------- |
|
97 // |
|
98 |
|
99 void RContentBuilder::Close() |
|
100 { |
|
101 //destroy pointer array content |
|
102 ResetAndDestroy(); |
|
103 |
|
104 //and close array (parent class) |
|
105 RPointerArray<HBufC8>::Close(); |
|
106 } |
|
107 |
|
108 |
|
109 |
|
110 // ----------------------------------------------------------------------------- |
|
111 // CApply::CApply() |
|
112 // ----------------------------------------------------------------------------- |
|
113 // |
|
114 |
|
115 CApply::CApply() |
|
116 { |
|
117 iElementType = EApply; |
|
118 iElementName.Set( PolicyLanguage::NativeLanguage::Expressions::Apply); |
|
119 |
|
120 iSaveType = ESubElement; |
|
121 } |
|
122 |
|
123 // ----------------------------------------------------------------------------- |
|
124 // CApply::~CApply() |
|
125 // ----------------------------------------------------------------------------- |
|
126 // |
|
127 |
|
128 CApply::~CApply() |
|
129 { |
|
130 delete iResponseValue; |
|
131 delete iFunctionId; |
|
132 } |
|
133 |
|
134 // ----------------------------------------------------------------------------- |
|
135 // CApply::NewL() |
|
136 // ----------------------------------------------------------------------------- |
|
137 // |
|
138 |
|
139 CApply * CApply::NewL() |
|
140 { |
|
141 CApply * self = new (ELeave) CApply(); |
|
142 |
|
143 CleanupStack::PushL( self); |
|
144 self->ConstructL(); |
|
145 CleanupStack::Pop ( self); |
|
146 |
|
147 return self; |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CApply::ConstructL() |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 |
|
155 void CApply::ConstructL() |
|
156 { |
|
157 iResponseValue = CAttributeValue::NewL(); |
|
158 } |
|
159 |
|
160 // ----------------------------------------------------------------------------- |
|
161 // CApply::IdentificateType() |
|
162 // ----------------------------------------------------------------------------- |
|
163 // |
|
164 |
|
165 TBool CApply::IdentificateType( const TDesC8& aElementName) |
|
166 { |
|
167 return ( aElementName == PolicyLanguage::NativeLanguage::Expressions::Apply); |
|
168 } |
|
169 |
|
170 // ----------------------------------------------------------------------------- |
|
171 // CApply::DecodeElementL |
|
172 // ----------------------------------------------------------------------------- |
|
173 // |
|
174 |
|
175 HBufC8 * CApply::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
176 { |
|
177 RDEBUG("PolicyEngineServer: Decode Apply element"); |
|
178 |
|
179 __ASSERT_ALWAYS ( iFunctionId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
180 |
|
181 //reserve all... |
|
182 CheckAllElementsL(); |
|
183 TElementReserver reserver( Container()); |
|
184 |
|
185 TInt size = 9; |
|
186 |
|
187 size += 2 * PolicyLanguage::Expressions::Apply[ aLanguage].Length(); |
|
188 |
|
189 size += PolicyLanguage::Expressions::FunctionId[ aLanguage].Length(); |
|
190 |
|
191 const TDesC8& functionId = SelectCorrectValue( aLanguage, *iFunctionId); |
|
192 size += functionId.Length(); |
|
193 |
|
194 RContentBuilder builder; |
|
195 CleanupClosePushL( builder); |
|
196 |
|
197 for ( TInt i(0); i < ElementCount(); i++) |
|
198 { |
|
199 CElementBase * element = Element(i); |
|
200 |
|
201 if ( element->ElementType() == EApply ) |
|
202 { |
|
203 builder.AddContentL( DecodeElementOrIdL( aLanguage, element, aMode)); |
|
204 } |
|
205 else |
|
206 { |
|
207 builder.AddContentL( DecodeElementOrIdL( aLanguage, element, EFullMode)); |
|
208 } |
|
209 |
|
210 } |
|
211 |
|
212 HBufC8* applies = builder.ContentL(); |
|
213 CleanupStack::PopAndDestroy( &builder); |
|
214 CleanupStack::PushL( applies); |
|
215 |
|
216 if (applies) size += applies->Length(); |
|
217 |
|
218 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
219 TPtr8 ptr = hbuf->Des(); |
|
220 |
|
221 ptr.Append('<'); |
|
222 ptr.Append(PolicyLanguage::Expressions::Apply[ aLanguage]); |
|
223 ptr.Append(' '); |
|
224 ptr.Append(PolicyLanguage::Expressions::FunctionId[ aLanguage]); |
|
225 ptr.Append( _L8("=\"")); |
|
226 ptr.Append( functionId); |
|
227 ptr.Append( _L8("\">")); |
|
228 if (applies) ptr.Append(*applies); |
|
229 ptr.Append(_L8("</")); |
|
230 ptr.Append(PolicyLanguage::Expressions::Apply[ aLanguage]); |
|
231 ptr.Append('>'); |
|
232 |
|
233 CleanupStack::Pop( hbuf); |
|
234 CleanupStack::PopAndDestroy( applies); |
|
235 |
|
236 reserver.Release(); |
|
237 |
|
238 |
|
239 return hbuf; |
|
240 } |
|
241 |
|
242 // ----------------------------------------------------------------------------- |
|
243 // CApply::AddAttributeL |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 |
|
247 void CApply::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
248 { |
|
249 if ( aName == PolicyLanguage::NativeLanguage::Expressions::FunctionId) |
|
250 { |
|
251 aParser->HandleErrorL( iFunctionId , ParserErrors::UnexpectedAttribute, aName); |
|
252 iFunctionId = aValue.AllocL(); |
|
253 aParser->CheckFunctionIdL( EApply, *iFunctionId); |
|
254 } |
|
255 else |
|
256 { |
|
257 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName ); |
|
258 } |
|
259 } |
|
260 |
|
261 // ----------------------------------------------------------------------------- |
|
262 // CApply::AddElementL |
|
263 // ----------------------------------------------------------------------------- |
|
264 // |
|
265 |
|
266 void CApply::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
267 { |
|
268 TNativeElementTypes type = aElement->ElementType(); |
|
269 |
|
270 if ( type == EApply || |
|
271 type == EAttributeValue || |
|
272 type == ESubjectAttributeDesignator || |
|
273 type == EEnvironmentAttributeDesignator || |
|
274 type == EResourceAttributeDesignator || |
|
275 type == EActionAttributeDesignator ) |
|
276 { |
|
277 AddToElementListL( aElement, ETrue); |
|
278 } |
|
279 else |
|
280 { |
|
281 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
282 } |
|
283 } |
|
284 |
|
285 // ----------------------------------------------------------------------------- |
|
286 // CApply::AddIdElementL |
|
287 // ----------------------------------------------------------------------------- |
|
288 // |
|
289 |
|
290 void CApply::AddIdElementL( CElementBase * aElement) |
|
291 { |
|
292 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
293 |
|
294 AddToElementListL( aElement, EFalse); |
|
295 } |
|
296 |
|
297 // ----------------------------------------------------------------------------- |
|
298 // CApply::ValidElement |
|
299 // ----------------------------------------------------------------------------- |
|
300 // |
|
301 |
|
302 TBool CApply::ValidElement() |
|
303 { |
|
304 TBool returnValue = EFalse; |
|
305 |
|
306 //function id is needed... |
|
307 if ( iFunctionId) |
|
308 { |
|
309 returnValue = FunctionHelper::IsAcceptableParamsForFunction( *iFunctionId, Container()); |
|
310 } |
|
311 |
|
312 return returnValue; |
|
313 } |
|
314 |
|
315 // ----------------------------------------------------------------------------- |
|
316 // CApply::ApplyValueL |
|
317 // ----------------------------------------------------------------------------- |
|
318 // |
|
319 |
|
320 CAttributeValue * CApply::ApplyValueL( CPolicyProcessor* aPolicyProcessor) |
|
321 { |
|
322 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
323 |
|
324 //reserve elements |
|
325 CheckAllElementsL(); |
|
326 TElementReserver reserver( Container()); |
|
327 |
|
328 //create parameter list add it cleanup stack |
|
329 RParameterList params; |
|
330 CleanupClosePushL( params); |
|
331 |
|
332 //search attributedesignators and apply elements |
|
333 for (TInt i(0); i < ElementCount(); i++) |
|
334 { |
|
335 CElementBase * element = Element( i); |
|
336 |
|
337 switch ( element->ElementType()) |
|
338 { |
|
339 case EApply: |
|
340 { |
|
341 //get parameter value from apply-element and append it parameter list |
|
342 params.AppendL( ((CApply*)element)->ApplyValueL( aPolicyProcessor)); |
|
343 } |
|
344 break; |
|
345 case ESubjectAttributeDesignator: |
|
346 case EEnvironmentAttributeDesignator: |
|
347 case EResourceAttributeDesignator: |
|
348 case EActionAttributeDesignator: |
|
349 { |
|
350 //get parameter value from request context (via attribute designators) |
|
351 CAttribute* attribute = ((CAttributeDesignator*) element)->GetAttributeFromRequestContext( aPolicyProcessor); |
|
352 |
|
353 if( attribute ) |
|
354 { |
|
355 params.AppendL( attribute->AttributeValue()); |
|
356 } |
|
357 |
|
358 if ( !attribute) |
|
359 { |
|
360 RDEBUG("PolicyEngineServer: PolicyProcessor: attribute not found"); |
|
361 |
|
362 // aPolicyProcessor->HandleErrorL( RequestErrors::MissingAttribute ); |
|
363 } |
|
364 |
|
365 //append value to paramer list |
|
366 //params.AppendL( attribute->AttributeValue()); |
|
367 } |
|
368 break; |
|
369 case EAttributeValue: |
|
370 { |
|
371 //attribute value is valid parameter type |
|
372 params.AppendL( (CAttributeValue*)element); |
|
373 } |
|
374 break; |
|
375 default: |
|
376 User::Panic( Panics::PolicyExecutionPanic, KErrAbort); |
|
377 break; |
|
378 } |
|
379 } |
|
380 |
|
381 //execute function |
|
382 aPolicyProcessor->FunctionL( *iFunctionId, params, iResponseValue ); |
|
383 |
|
384 CleanupStack::PopAndDestroy( ¶ms); //params.Close() |
|
385 reserver.Release(); |
|
386 |
|
387 return iResponseValue; |
|
388 |
|
389 #endif //#ifndef __POLICY_BASE_CREATOR_TOOL |
|
390 } |
|
391 |
|
392 |
|
393 |
|
394 // ----------------------------------------------------------------------------- |
|
395 // CApply::ReturnDataType |
|
396 // ----------------------------------------------------------------------------- |
|
397 // |
|
398 const TPtrC8 CApply::ReturnDataType() |
|
399 { |
|
400 __ASSERT_ALWAYS ( iFunctionId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
401 |
|
402 using namespace PolicyLanguage::NativeLanguage::Functions; |
|
403 |
|
404 TPtrC8 ptr; |
|
405 |
|
406 //set return data tpye |
|
407 if ( *iFunctionId == FunctionStringEqualId || |
|
408 *iFunctionId == FunctionBooleanEqualId || |
|
409 |
|
410 *iFunctionId == FunctionOr || |
|
411 *iFunctionId == FunctionAnd || |
|
412 *iFunctionId == FunctionNot || |
|
413 |
|
414 *iFunctionId == FunctionCertificatedSession || |
|
415 *iFunctionId == FunctionUserAcceptCorpPolicy || |
|
416 *iFunctionId == FunctionRuleTargetStructure ) |
|
417 { |
|
418 ptr.Set( PolicyLanguage::NativeLanguage::AttributeValues::BooleanDataType); |
|
419 } |
|
420 |
|
421 return ptr; |
|
422 } |
|
423 |
|
424 // ----------------------------------------------------------------------------- |
|
425 // CCondition::CCondition |
|
426 // ----------------------------------------------------------------------------- |
|
427 // |
|
428 |
|
429 CCondition::CCondition() |
|
430 { |
|
431 iElementType = ECondition; |
|
432 iElementName.Set( PolicyLanguage::NativeLanguage::Expressions::Condition); |
|
433 |
|
434 iSaveType = ESubElement; |
|
435 } |
|
436 |
|
437 // ----------------------------------------------------------------------------- |
|
438 // CCondition::~CCondition |
|
439 // ----------------------------------------------------------------------------- |
|
440 // |
|
441 CCondition::~CCondition() |
|
442 { |
|
443 } |
|
444 |
|
445 // ----------------------------------------------------------------------------- |
|
446 // CCondition::NewL |
|
447 // ----------------------------------------------------------------------------- |
|
448 // |
|
449 CCondition * CCondition::NewL() |
|
450 { |
|
451 return new (ELeave) CCondition(); |
|
452 } |
|
453 |
|
454 // ----------------------------------------------------------------------------- |
|
455 // CCondition::IdentificateType |
|
456 // ----------------------------------------------------------------------------- |
|
457 // |
|
458 TBool CCondition::IdentificateType( const TDesC8& aElementName) |
|
459 { |
|
460 return ( aElementName == PolicyLanguage::NativeLanguage::Expressions::Condition); |
|
461 } |
|
462 |
|
463 // ----------------------------------------------------------------------------- |
|
464 // CCondition::DecodeElementL |
|
465 // ----------------------------------------------------------------------------- |
|
466 // |
|
467 |
|
468 HBufC8 * CCondition::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
469 { |
|
470 RDEBUG("PolicyEngineServer: Decode Condition element"); |
|
471 |
|
472 |
|
473 __ASSERT_ALWAYS ( iExpression, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
474 |
|
475 CheckAllElementsL(); |
|
476 TElementReserver reserver( Container()); |
|
477 |
|
478 TInt size(5); |
|
479 TPtrC8 conditionPtr = PolicyLanguage::Expressions::Condition[ aLanguage]; |
|
480 size += 2 * conditionPtr.Length(); |
|
481 |
|
482 HBufC8 * expression = DecodeElementOrIdL( aLanguage, iExpression, aMode); |
|
483 CleanupStack::PushL( expression); |
|
484 |
|
485 size += expression->Length(); |
|
486 |
|
487 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
488 TPtr8 ptr = hbuf->Des(); |
|
489 |
|
490 ptr.Append( '<'); |
|
491 ptr.Append( conditionPtr); |
|
492 ptr.Append( '>'); |
|
493 ptr.Append( *expression); |
|
494 ptr.Append(_L8("</")); |
|
495 ptr.Append( conditionPtr); |
|
496 ptr.Append( '>'); |
|
497 |
|
498 CleanupStack::Pop( hbuf); |
|
499 CleanupStack::PopAndDestroy( expression); |
|
500 |
|
501 reserver.Release(); |
|
502 |
|
503 return hbuf; |
|
504 } |
|
505 |
|
506 // ----------------------------------------------------------------------------- |
|
507 // CCondition::AddElementL |
|
508 // ----------------------------------------------------------------------------- |
|
509 // |
|
510 void CCondition::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
511 { |
|
512 if ( aElement->ElementType() == EApply ) |
|
513 { |
|
514 aParser->HandleErrorL( iExpression, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
515 AddToElementListL( aElement, ETrue); |
|
516 iExpression = aElement; |
|
517 } |
|
518 else |
|
519 { |
|
520 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
521 } |
|
522 } |
|
523 |
|
524 // ----------------------------------------------------------------------------- |
|
525 // CCondition::AddIdElementL |
|
526 // ----------------------------------------------------------------------------- |
|
527 // |
|
528 void CCondition::AddIdElementL( CElementBase * aElement) |
|
529 { |
|
530 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
531 |
|
532 iExpression = aElement; |
|
533 AddToElementListL( aElement, EFalse); |
|
534 } |
|
535 |
|
536 // ----------------------------------------------------------------------------- |
|
537 // CCondition::ValidElement |
|
538 // ----------------------------------------------------------------------------- |
|
539 // |
|
540 |
|
541 TBool CCondition::ValidElement() |
|
542 { |
|
543 TBool returnValue = EFalse; |
|
544 |
|
545 if ( iExpression) |
|
546 { |
|
547 TPtrC8 dataType = ((CApply*) iExpression)->ReturnDataType(); |
|
548 |
|
549 if ( dataType == PolicyLanguage::NativeLanguage::AttributeValues::BooleanDataType) |
|
550 { |
|
551 returnValue = ETrue; |
|
552 } |
|
553 } |
|
554 |
|
555 return returnValue; |
|
556 } |
|
557 |
|
558 |
|
559 // ----------------------------------------------------------------------------- |
|
560 // CCondition::ConditionValuement |
|
561 // ----------------------------------------------------------------------------- |
|
562 //¨ |
|
563 |
|
564 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
565 |
|
566 TMatchResponse CCondition::ConditionValueL( CPolicyProcessor* aPolicyProcessor) |
|
567 { |
|
568 RDEBUG("PolicyEngineServer: Evaluate condition value - start"); |
|
569 |
|
570 __ASSERT_ALWAYS ( iExpression, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
571 |
|
572 //default response |
|
573 TMatchResponse response = EIndeterminate; |
|
574 |
|
575 //check element |
|
576 TElementReserver reserver( iExpression); |
|
577 CPolicyStorage::PolicyStorage()->CheckElementL( iExpression); |
|
578 |
|
579 //apply-value from apply element |
|
580 CAttributeValue * element = iExpression->ApplyValueL( aPolicyProcessor); |
|
581 |
|
582 //check that respose element is attribute... |
|
583 if ( element->ElementType() == EAttributeValue ) |
|
584 { |
|
585 CDataType * data = element->Data(); |
|
586 |
|
587 //..attribute type should boolean |
|
588 if ( data->DataType( ENative) == PolicyLanguage::NativeLanguage::AttributeValues::BooleanDataType) |
|
589 { |
|
590 if ( data->Value() == PolicyLanguage::NativeLanguage::AttributeValues::BooleanTrue) |
|
591 { |
|
592 RDEBUG("PolicyEngineServer: Condition value is TRUE"); |
|
593 response = EMatch; |
|
594 } |
|
595 else |
|
596 { |
|
597 RDEBUG("PolicyEngineServer: Condition value is FALSE"); |
|
598 response = EUnMatch; |
|
599 } |
|
600 } |
|
601 } |
|
602 |
|
603 reserver.Release(); |
|
604 |
|
605 //response... |
|
606 RDEBUG("PolicyEngineServer: Evaluate condition value - end"); |
|
607 return response; |
|
608 } |
|
609 |
|
610 #endif // __POLICY_BASE_CREATOR_TOOL |
|
611 |
|
612 // ----------------------------------------------------------------------------- |
|
613 // CPolicySet::CPolicySet |
|
614 // ----------------------------------------------------------------------------- |
|
615 // |
|
616 CPolicySet::CPolicySet() |
|
617 { |
|
618 iElementType = EPolicySet; |
|
619 iElementName.Set( PolicyLanguage::NativeLanguage::PolicySet::PolicySet); |
|
620 } |
|
621 |
|
622 // ----------------------------------------------------------------------------- |
|
623 // CPolicySet::~CPolicySet |
|
624 // ----------------------------------------------------------------------------- |
|
625 // |
|
626 CPolicySet::~CPolicySet() |
|
627 { |
|
628 delete iPolicySetId; |
|
629 delete iPolicyCompiningAlg; |
|
630 } |
|
631 |
|
632 // ----------------------------------------------------------------------------- |
|
633 // CPolicySet::NewL |
|
634 // ----------------------------------------------------------------------------- |
|
635 // |
|
636 CPolicySet * CPolicySet::NewL() |
|
637 { |
|
638 return new (ELeave) CPolicySet(); |
|
639 } |
|
640 |
|
641 // ----------------------------------------------------------------------------- |
|
642 // CPolicySet::IdentificateType |
|
643 // ----------------------------------------------------------------------------- |
|
644 // |
|
645 TBool CPolicySet::IdentificateType( const TDesC8& aElementName) |
|
646 { |
|
647 return ( aElementName == PolicyLanguage::NativeLanguage::PolicySet::PolicySet); |
|
648 } |
|
649 |
|
650 // ----------------------------------------------------------------------------- |
|
651 // CPolicySet::AddAttributeL |
|
652 // ----------------------------------------------------------------------------- |
|
653 // |
|
654 void CPolicySet::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
655 { |
|
656 if ( aName == PolicyLanguage::NativeLanguage::PolicySet::PolicySetId) |
|
657 { |
|
658 aParser->HandleErrorL( iPolicySetId , ParserErrors::UnexpectedAttribute, aName); |
|
659 iPolicySetId = aValue.AllocL(); |
|
660 iExternalId = iPolicySetId; |
|
661 aParser->CheckExternalIdL( iExternalId); |
|
662 } |
|
663 else |
|
664 if ( aName == PolicyLanguage::NativeLanguage::PolicySet::PolicyCombiningAlgId) |
|
665 { |
|
666 aParser->HandleErrorL( iPolicyCompiningAlg, ParserErrors::UnexpectedAttribute, aName); |
|
667 aParser->CheckCompiningAlgorithmsL( EPolicySet, aValue); |
|
668 iPolicyCompiningAlg = aValue.AllocL(); |
|
669 } |
|
670 else |
|
671 { |
|
672 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName ); |
|
673 } |
|
674 } |
|
675 |
|
676 // ----------------------------------------------------------------------------- |
|
677 // CPolicySet::AddElementL |
|
678 // ----------------------------------------------------------------------------- |
|
679 // |
|
680 void CPolicySet::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
681 { |
|
682 if ( aElement->ElementType() == ETarget ) |
|
683 { |
|
684 aParser->HandleErrorL( iTarget, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
685 AddToElementListL( aElement, ETrue); |
|
686 iTarget = aElement; |
|
687 } |
|
688 else if ( aElement->ElementType() == EPolicy || aElement->ElementType() == EPolicySet) |
|
689 { |
|
690 AddToElementListL( aElement, ETrue); |
|
691 } |
|
692 else |
|
693 if ( aElement->ElementType() == EDescription ) |
|
694 { |
|
695 aParser->HandleErrorL( iDescription, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
696 AddToElementListL( aElement, ETrue); |
|
697 iDescription = aElement; |
|
698 } |
|
699 else |
|
700 { |
|
701 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
702 } |
|
703 }; |
|
704 |
|
705 // ----------------------------------------------------------------------------- |
|
706 // CPolicySet::AddIdElementL |
|
707 // ----------------------------------------------------------------------------- |
|
708 // |
|
709 |
|
710 void CPolicySet::AddIdElementL( CElementBase * aElement) |
|
711 { |
|
712 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
713 |
|
714 if ( aElement->ElementType() == ETarget ) |
|
715 { |
|
716 iTarget = aElement; |
|
717 } |
|
718 else |
|
719 if ( aElement->ElementType() == EDescription ) |
|
720 { |
|
721 iDescription = aElement; |
|
722 } |
|
723 |
|
724 AddToElementListL( aElement, EFalse); |
|
725 } |
|
726 |
|
727 // ----------------------------------------------------------------------------- |
|
728 // CPolicySet::DecodeElementL |
|
729 // ----------------------------------------------------------------------------- |
|
730 // |
|
731 |
|
732 HBufC8 * CPolicySet::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
733 { |
|
734 RDEBUG("PolicyEngineServer: Decode PolicySet element"); |
|
735 |
|
736 __ASSERT_ALWAYS ( iPolicySetId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
737 __ASSERT_ALWAYS ( iPolicyCompiningAlg, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
738 |
|
739 CheckAllElementsL(); |
|
740 TElementReserver reserver( Container()); |
|
741 |
|
742 TInt size = 16; |
|
743 |
|
744 size += 2 * PolicyLanguage::PolicySet::PolicySet[ aLanguage].Length(); |
|
745 |
|
746 size += PolicyLanguage::PolicySet::PolicySetId[ aLanguage].Length(); |
|
747 size += iPolicySetId->Length(); |
|
748 |
|
749 size += PolicyLanguage::PolicySet::PolicyCombiningAlgId[ aLanguage].Length(); |
|
750 |
|
751 |
|
752 const TDesC8& policyCompiningAlg = SelectCorrectValue( aLanguage, *iPolicyCompiningAlg); |
|
753 size += policyCompiningAlg.Length(); |
|
754 |
|
755 RContentBuilder builder; |
|
756 CleanupClosePushL( builder); |
|
757 |
|
758 for ( TInt i(0); i < ElementCount(); i++) |
|
759 { |
|
760 CElementBase * element = Element(i); |
|
761 builder.AddContentL( DecodeElementOrIdL( aLanguage, element, aMode)); |
|
762 } |
|
763 |
|
764 HBufC8* rules = builder.ContentL(); |
|
765 CleanupStack::PopAndDestroy( &builder); |
|
766 CleanupStack::PushL(rules); |
|
767 |
|
768 if (rules) size += rules->Length(); |
|
769 |
|
770 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
771 TPtr8 ptr = hbuf->Des(); |
|
772 |
|
773 ptr.Append( '<'); |
|
774 ptr.Append( PolicyLanguage::PolicySet::PolicySet[ aLanguage]); |
|
775 ptr.Append( ' '); |
|
776 ptr.Append( PolicyLanguage::PolicySet::PolicySetId[ aLanguage]); |
|
777 ptr.Append( _L8("=\"")); |
|
778 ptr.Append( *iPolicySetId); |
|
779 ptr.Append( _L8("\" ")); |
|
780 ptr.Append( PolicyLanguage::PolicySet::PolicyCombiningAlgId[ aLanguage]); |
|
781 ptr.Append( _L8("=\"")); |
|
782 ptr.Append( policyCompiningAlg); |
|
783 ptr.Append( _L8("\">")); |
|
784 |
|
785 if (rules) |
|
786 { |
|
787 ptr.Append(*rules); |
|
788 } |
|
789 |
|
790 ptr.Append( _L8("</")); |
|
791 ptr.Append( PolicyLanguage::PolicySet::PolicySet[ aLanguage]); |
|
792 ptr.Append( '>'); |
|
793 |
|
794 CleanupStack::Pop( hbuf); |
|
795 CleanupStack::PopAndDestroy( rules); |
|
796 |
|
797 reserver.Release(); |
|
798 |
|
799 return hbuf; |
|
800 } |
|
801 |
|
802 // ----------------------------------------------------------------------------- |
|
803 // CPolicySet::ValidElement |
|
804 // ----------------------------------------------------------------------------- |
|
805 // |
|
806 |
|
807 TBool CPolicySet::ValidElement() |
|
808 { |
|
809 return iPolicySetId && iPolicyCompiningAlg; |
|
810 } |
|
811 |
|
812 // ----------------------------------------------------------------------------- |
|
813 // CPolicySet::MatchL |
|
814 // ----------------------------------------------------------------------------- |
|
815 // |
|
816 |
|
817 |
|
818 TMatchResponse CPolicySet::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
819 { |
|
820 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
821 |
|
822 CPolicyStorage::PolicyStorage()->CheckElementL( this); |
|
823 RDEBUG8_2("PolicyEngineServer: %S match evaluation started", ExternalId()); |
|
824 |
|
825 //check policyset target |
|
826 if ( iTarget) |
|
827 { |
|
828 //reserve eleemnt |
|
829 TElementReserver targetReserver( iTarget); |
|
830 CPolicyStorage::PolicyStorage()->CheckElementL( iTarget); |
|
831 |
|
832 //and check target match |
|
833 TMatchResponse response = iTarget->MatchL( aPolicyProcessor); |
|
834 targetReserver.Release(); |
|
835 |
|
836 if ( response == EUnMatch ) |
|
837 { |
|
838 return ENotApplicable; |
|
839 } |
|
840 } |
|
841 |
|
842 __ASSERT_ALWAYS ( iPolicyCompiningAlg, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
843 |
|
844 //set up combining algorithm |
|
845 TCombiningAlgorith combiner( *iPolicyCompiningAlg); |
|
846 |
|
847 //loop all policies and policysets and combine their results |
|
848 for ( TInt i(0); i < ElementCount(); i++) |
|
849 { |
|
850 CElementBase * element = Element(i); |
|
851 TElementReserver elementReserver( element); |
|
852 |
|
853 //select only policies and sets |
|
854 if ( element->ElementType() == EPolicy || element->ElementType() == EPolicySet) |
|
855 { |
|
856 CPolicyStorage::PolicyStorage()->CheckElementL( element ); |
|
857 combiner.AddInput( element->MatchL( aPolicyProcessor)); |
|
858 } |
|
859 |
|
860 elementReserver.Release(); |
|
861 } |
|
862 |
|
863 RDEBUG8_2("PolicyEngineServer: %S match evaluation finished", ExternalId()); |
|
864 |
|
865 return combiner.Result(); |
|
866 |
|
867 #endif // __POLICY_BASE_CREATOR_TOOL |
|
868 } |
|
869 |
|
870 |
|
871 // ----------------------------------------------------------------------------- |
|
872 // CPolicy::CPolicy |
|
873 // ----------------------------------------------------------------------------- |
|
874 // |
|
875 |
|
876 CPolicy::CPolicy() |
|
877 { |
|
878 iElementType = EPolicy; |
|
879 iElementName.Set( PolicyLanguage::NativeLanguage::Policy::Policy); |
|
880 } |
|
881 |
|
882 // ----------------------------------------------------------------------------- |
|
883 // CPolicy::~CPolicy |
|
884 // ----------------------------------------------------------------------------- |
|
885 // |
|
886 |
|
887 CPolicy::~CPolicy() |
|
888 { |
|
889 delete iPolicyId; |
|
890 delete iRuleCompiningAlg; |
|
891 } |
|
892 |
|
893 // ----------------------------------------------------------------------------- |
|
894 // CPolicy::NewL |
|
895 // ----------------------------------------------------------------------------- |
|
896 // |
|
897 |
|
898 CPolicy * CPolicy::NewL() |
|
899 { |
|
900 return new (ELeave) CPolicy(); |
|
901 } |
|
902 |
|
903 // ----------------------------------------------------------------------------- |
|
904 // CPolicy::IdentificateType |
|
905 // ----------------------------------------------------------------------------- |
|
906 // |
|
907 |
|
908 TBool CPolicy::IdentificateType( const TDesC8& aElementName) |
|
909 { |
|
910 return ( aElementName == PolicyLanguage::NativeLanguage::Policy::Policy); |
|
911 } |
|
912 |
|
913 // ----------------------------------------------------------------------------- |
|
914 // CPolicy::AddAttributeL |
|
915 // ----------------------------------------------------------------------------- |
|
916 // |
|
917 |
|
918 void CPolicy::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
919 { |
|
920 if ( aName == PolicyLanguage::NativeLanguage::Policy::PolicyId) |
|
921 { |
|
922 aParser->HandleErrorL( iPolicyId , ParserErrors::UnexpectedAttribute, aName); |
|
923 iPolicyId = aValue.AllocL(); |
|
924 iExternalId = iPolicyId; |
|
925 aParser->CheckExternalIdL( iExternalId); |
|
926 } |
|
927 else |
|
928 if ( aName == PolicyLanguage::NativeLanguage::Policy::RuleCombiningAlgId) |
|
929 { |
|
930 aParser->HandleErrorL( iRuleCompiningAlg, ParserErrors::UnexpectedAttribute, aName); |
|
931 aParser->CheckCompiningAlgorithmsL( EPolicy, aValue); |
|
932 iRuleCompiningAlg = aValue.AllocL(); |
|
933 } |
|
934 else |
|
935 { |
|
936 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName); |
|
937 } |
|
938 } |
|
939 |
|
940 // ----------------------------------------------------------------------------- |
|
941 // CPolicy::AddElementL |
|
942 // ----------------------------------------------------------------------------- |
|
943 // |
|
944 void CPolicy::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
945 { |
|
946 if ( aElement->ElementType() == ETarget ) |
|
947 { |
|
948 aParser->HandleErrorL( iTarget, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
949 AddToElementListL( aElement, ETrue); |
|
950 iTarget = aElement; |
|
951 } |
|
952 else |
|
953 if ( aElement->ElementType() == EDescription ) |
|
954 { |
|
955 aParser->HandleErrorL( iDescription, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
956 AddToElementListL( aElement, ETrue); |
|
957 iDescription = aElement; |
|
958 } |
|
959 else if ( aElement->ElementType() == ERule ) |
|
960 { |
|
961 AddToElementListL( aElement, ETrue); |
|
962 } |
|
963 else |
|
964 { |
|
965 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
966 } |
|
967 }; |
|
968 |
|
969 // ----------------------------------------------------------------------------- |
|
970 // CPolicy::AddIdElementL |
|
971 // ----------------------------------------------------------------------------- |
|
972 // |
|
973 |
|
974 void CPolicy::AddIdElementL( CElementBase * aElement) |
|
975 { |
|
976 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
977 |
|
978 if ( aElement->ElementType() == ETarget ) |
|
979 { |
|
980 iTarget = aElement; |
|
981 } |
|
982 else |
|
983 if ( aElement->ElementType() == EDescription ) |
|
984 { |
|
985 iDescription = aElement; |
|
986 } |
|
987 |
|
988 AddToElementListL( aElement, EFalse); |
|
989 } |
|
990 |
|
991 // ----------------------------------------------------------------------------- |
|
992 // CPolicy::ValidElement |
|
993 // ----------------------------------------------------------------------------- |
|
994 // |
|
995 |
|
996 TBool CPolicy::ValidElement() |
|
997 { |
|
998 return iPolicyId && iRuleCompiningAlg; |
|
999 } |
|
1000 |
|
1001 // ----------------------------------------------------------------------------- |
|
1002 // CPolicy::DecodeElementL |
|
1003 // ----------------------------------------------------------------------------- |
|
1004 // |
|
1005 |
|
1006 HBufC8 * CPolicy::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
1007 { |
|
1008 RDEBUG("PolicyEngineServer: Decode Policy element"); |
|
1009 |
|
1010 |
|
1011 __ASSERT_ALWAYS ( iPolicyId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1012 __ASSERT_ALWAYS ( iRuleCompiningAlg, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1013 |
|
1014 CheckAllElementsL(); |
|
1015 TElementReserver reserver( Container()); |
|
1016 |
|
1017 |
|
1018 TInt size = 16; |
|
1019 |
|
1020 size += 2 * PolicyLanguage::Policy::Policy[ aLanguage].Length(); |
|
1021 |
|
1022 size += PolicyLanguage::Policy::PolicyId[ aLanguage].Length(); |
|
1023 const TDesC8& policyId = SelectCorrectValue( aLanguage, *iPolicyId); |
|
1024 size += policyId.Length(); |
|
1025 |
|
1026 size += PolicyLanguage::Policy::RuleCombiningAlgId[ aLanguage].Length(); |
|
1027 const TDesC8& ruleCompiningAlg = SelectCorrectValue( aLanguage, *iRuleCompiningAlg); |
|
1028 size += ruleCompiningAlg.Length(); |
|
1029 |
|
1030 |
|
1031 HBufC8 * rules = NULL; |
|
1032 CleanupStack::PushL(rules); |
|
1033 |
|
1034 for ( TInt i(0); i < ElementCount(); i++) |
|
1035 { |
|
1036 CElementBase * element = Element(i); |
|
1037 |
|
1038 HBufC8 * decode = DecodeElementOrIdL( aLanguage, element, aMode); |
|
1039 CleanupStack::PushL( decode); |
|
1040 |
|
1041 if ( rules ) |
|
1042 { |
|
1043 rules = rules->ReAllocL( rules->Length() + decode->Length() + 10); |
|
1044 } |
|
1045 else |
|
1046 { |
|
1047 rules = HBufC8::NewL( decode->Length() + 10); |
|
1048 } |
|
1049 |
|
1050 rules->Des().Append( *decode); |
|
1051 CleanupStack::PopAndDestroy(); //decode |
|
1052 CleanupStack::Pop(); //old rules or null... |
|
1053 CleanupStack::PushL(rules); |
|
1054 } |
|
1055 //rules or null |
|
1056 |
|
1057 if (rules) size += rules->Length(); |
|
1058 |
|
1059 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
1060 TPtr8 ptr = hbuf->Des(); |
|
1061 |
|
1062 ptr.Append('<'); |
|
1063 ptr.Append(PolicyLanguage::Policy::Policy[ aLanguage]); |
|
1064 ptr.Append(' '); |
|
1065 ptr.Append(PolicyLanguage::Policy::PolicyId[ aLanguage]); |
|
1066 ptr.Append( _L8("=\"")); |
|
1067 ptr.Append( policyId); |
|
1068 ptr.Append( _L8("\" ")); |
|
1069 ptr.Append(PolicyLanguage::Policy::RuleCombiningAlgId[ aLanguage]); |
|
1070 ptr.Append( _L8("=\"")); |
|
1071 ptr.Append( ruleCompiningAlg); |
|
1072 ptr.Append( _L8("\">")); |
|
1073 if (rules) ptr.Append(*rules); |
|
1074 ptr.Append(_L8("</")); |
|
1075 ptr.Append(PolicyLanguage::Policy::Policy[ aLanguage]); |
|
1076 ptr.Append('>'); |
|
1077 |
|
1078 CleanupStack::Pop(); |
|
1079 CleanupStack::PopAndDestroy(); |
|
1080 |
|
1081 reserver.Release(); |
|
1082 |
|
1083 return hbuf; |
|
1084 } |
|
1085 |
|
1086 // ----------------------------------------------------------------------------- |
|
1087 // CPolicy:: |
|
1088 // ----------------------------------------------------------------------------- |
|
1089 // |
|
1090 |
|
1091 |
|
1092 TMatchResponse CPolicy::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
1093 { |
|
1094 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
1095 |
|
1096 CPolicyStorage::PolicyStorage()->CheckElementL( this); |
|
1097 RDEBUG8_2("PolicyEngineServer: %S match evaluation started", ExternalId()); |
|
1098 |
|
1099 if ( iTarget) |
|
1100 { |
|
1101 TElementReserver targetReserver( iTarget); |
|
1102 CPolicyStorage::PolicyStorage()->CheckElementL( iTarget); |
|
1103 TMatchResponse response = iTarget->MatchL( aPolicyProcessor); |
|
1104 targetReserver.Release(); |
|
1105 |
|
1106 if ( response == EUnMatch ) |
|
1107 { |
|
1108 return ENotApplicable; |
|
1109 } |
|
1110 } |
|
1111 |
|
1112 __ASSERT_ALWAYS ( iRuleCompiningAlg, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1113 |
|
1114 TCombiningAlgorith combiner( *iRuleCompiningAlg); |
|
1115 |
|
1116 for ( TInt i(0); i < ElementCount(); i++) |
|
1117 { |
|
1118 CElementBase * element = Element(i); |
|
1119 TElementReserver elementReserver( element); |
|
1120 |
|
1121 if ( element->ElementType() == ERule) |
|
1122 { |
|
1123 CPolicyStorage::PolicyStorage()->CheckElementL( element); |
|
1124 CRule * rule = (CRule*) element; |
|
1125 combiner.AddInput( rule->MatchL( aPolicyProcessor), rule->Effect()); |
|
1126 } |
|
1127 |
|
1128 elementReserver.Release(); |
|
1129 } |
|
1130 |
|
1131 RDEBUG8_2("PolicyEngineServer: %S match evaluation finished", ExternalId()); |
|
1132 return combiner.Result(); |
|
1133 |
|
1134 #endif// __POLICY_BASE_CREATOR_TOOL |
|
1135 } |
|
1136 |
|
1137 |
|
1138 // ----------------------------------------------------------------------------- |
|
1139 // CAttribute:: |
|
1140 // ----------------------------------------------------------------------------- |
|
1141 // |
|
1142 |
|
1143 CAttribute::CAttribute() |
|
1144 { |
|
1145 iSaveType = ESubElement; |
|
1146 } |
|
1147 |
|
1148 // ----------------------------------------------------------------------------- |
|
1149 // CAttribute:: |
|
1150 // ----------------------------------------------------------------------------- |
|
1151 // |
|
1152 |
|
1153 CAttribute * CAttribute::NewL( const TDesC8& aAttributeId, const TBool& aAttributeValue) |
|
1154 { |
|
1155 CAttribute * self = new (ELeave) CAttribute(); |
|
1156 CleanupStack::PushL( self); |
|
1157 |
|
1158 using namespace PolicyLanguage::AttributeValues; |
|
1159 |
|
1160 //create attribute with true or false value |
|
1161 if ( aAttributeValue ) |
|
1162 { |
|
1163 self->ConstructL( aAttributeId, BooleanTrue[ENative], BooleanDataType[ENative]); |
|
1164 } |
|
1165 else |
|
1166 { |
|
1167 self->ConstructL( aAttributeId, BooleanFalse[ENative], BooleanDataType[ENative]); |
|
1168 } |
|
1169 |
|
1170 CleanupStack::Pop( self); |
|
1171 |
|
1172 return self; |
|
1173 } |
|
1174 |
|
1175 // ----------------------------------------------------------------------------- |
|
1176 // CAttribute:: |
|
1177 // ----------------------------------------------------------------------------- |
|
1178 // |
|
1179 |
|
1180 |
|
1181 CAttribute * CAttribute::NewL( const TDesC8& aAttributeId, const TDesC8& aAttributeValue, const TDesC8& aDataType) |
|
1182 { |
|
1183 CAttribute * self = new (ELeave) CAttribute(); |
|
1184 |
|
1185 CleanupStack::PushL( self); |
|
1186 self->ConstructL( aAttributeId, aAttributeValue, aDataType ); |
|
1187 CleanupStack::Pop( self); |
|
1188 |
|
1189 return self; |
|
1190 } |
|
1191 |
|
1192 // ----------------------------------------------------------------------------- |
|
1193 // CAttribute:: |
|
1194 // ----------------------------------------------------------------------------- |
|
1195 // |
|
1196 |
|
1197 |
|
1198 void CAttribute::ConstructL( const TDesC8& aAttributeId, const TDesC8& aAttributeValue, const TDesC8& aDataType) |
|
1199 { |
|
1200 iAttributeValue = CAttributeValue::NewL( aAttributeValue, aDataType); |
|
1201 iElementType = EAttribute; |
|
1202 |
|
1203 AddToElementListL( iAttributeValue, ETrue); |
|
1204 |
|
1205 iAttributeId = aAttributeId.AllocL(); |
|
1206 iDataType = aDataType.AllocL(); |
|
1207 } |
|
1208 |
|
1209 // ----------------------------------------------------------------------------- |
|
1210 // CAttribute:: |
|
1211 // ----------------------------------------------------------------------------- |
|
1212 // |
|
1213 |
|
1214 CAttribute::~CAttribute() |
|
1215 { |
|
1216 delete iDataType; |
|
1217 delete iAttributeId; |
|
1218 } |
|
1219 |
|
1220 // ----------------------------------------------------------------------------- |
|
1221 // CAttribute:: |
|
1222 // ----------------------------------------------------------------------------- |
|
1223 // |
|
1224 |
|
1225 CAttributeValue * CAttribute::AttributeValue() |
|
1226 { |
|
1227 return iAttributeValue; |
|
1228 } |
|
1229 |
|
1230 // ----------------------------------------------------------------------------- |
|
1231 // CAttribute:: |
|
1232 // ----------------------------------------------------------------------------- |
|
1233 // |
|
1234 |
|
1235 TDesC8& CAttribute::AttributeId() |
|
1236 { |
|
1237 return *iAttributeId; |
|
1238 } |
|
1239 |
|
1240 // ----------------------------------------------------------------------------- |
|
1241 // CAttribute:: |
|
1242 // ----------------------------------------------------------------------------- |
|
1243 // |
|
1244 |
|
1245 TDesC8& CAttribute::AttributeType() |
|
1246 { |
|
1247 return *iDataType; |
|
1248 } |
|
1249 |
|
1250 // ----------------------------------------------------------------------------- |
|
1251 // CRule:: |
|
1252 // ----------------------------------------------------------------------------- |
|
1253 // |
|
1254 |
|
1255 CRule::CRule() |
|
1256 { |
|
1257 iElementType = ERule; |
|
1258 iElementName.Set( PolicyLanguage::NativeLanguage::Rule::Rule); |
|
1259 } |
|
1260 |
|
1261 // ----------------------------------------------------------------------------- |
|
1262 // CRule:: |
|
1263 // ----------------------------------------------------------------------------- |
|
1264 // |
|
1265 |
|
1266 |
|
1267 CRule::~CRule() |
|
1268 { |
|
1269 delete iEffect; |
|
1270 delete iRuleId; |
|
1271 } |
|
1272 |
|
1273 // ----------------------------------------------------------------------------- |
|
1274 // CRule:: |
|
1275 // ----------------------------------------------------------------------------- |
|
1276 // |
|
1277 |
|
1278 |
|
1279 CRule * CRule::NewL() |
|
1280 { |
|
1281 return new (ELeave) CRule(); |
|
1282 } |
|
1283 |
|
1284 // ----------------------------------------------------------------------------- |
|
1285 // CRule:: |
|
1286 // ----------------------------------------------------------------------------- |
|
1287 // |
|
1288 |
|
1289 |
|
1290 TBool CRule::IdentificateType( const TDesC8& aElementName) |
|
1291 { |
|
1292 return ( aElementName == PolicyLanguage::NativeLanguage::Rule::Rule); |
|
1293 } |
|
1294 |
|
1295 // ----------------------------------------------------------------------------- |
|
1296 // CRule:: |
|
1297 // ----------------------------------------------------------------------------- |
|
1298 // |
|
1299 |
|
1300 |
|
1301 HBufC8 * CRule::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
1302 { |
|
1303 RDEBUG("PolicyEngineServer: Decode Rule element"); |
|
1304 |
|
1305 __ASSERT_ALWAYS ( iEffect, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1306 __ASSERT_ALWAYS ( iRuleId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1307 __ASSERT_ALWAYS ( iTarget, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1308 |
|
1309 CheckAllElementsL(); |
|
1310 TElementReserver reserver( Container()); |
|
1311 |
|
1312 TInt size = 16; |
|
1313 |
|
1314 size += 2 * PolicyLanguage::Rule::Rule[ aLanguage].Length(); |
|
1315 |
|
1316 size += PolicyLanguage::Rule::RuleId[ aLanguage].Length(); |
|
1317 const TDesC8& ruleId = SelectCorrectValue( aLanguage, *iRuleId); |
|
1318 size += ruleId.Length(); |
|
1319 |
|
1320 size += PolicyLanguage::Rule::Effect[ aLanguage].Length(); |
|
1321 const TDesC8& effect = SelectCorrectValue( aLanguage, *iEffect); |
|
1322 size += effect.Length(); |
|
1323 |
|
1324 HBufC8 * elements = NULL; |
|
1325 CleanupStack::PushL( elements); |
|
1326 |
|
1327 for ( TInt i(0); i < ElementCount(); i++) |
|
1328 { |
|
1329 CElementBase * element = Element(i); |
|
1330 |
|
1331 HBufC8 * decode = DecodeElementOrIdL( aLanguage, element, aMode); |
|
1332 |
|
1333 CleanupStack::PushL( decode); |
|
1334 |
|
1335 if ( elements) |
|
1336 { |
|
1337 elements = elements->ReAlloc( elements->Length() + decode->Length()); |
|
1338 } |
|
1339 else |
|
1340 { |
|
1341 elements = HBufC8::NewL( decode->Length() + 10); |
|
1342 } |
|
1343 |
|
1344 elements->Des().Append( *decode); |
|
1345 CleanupStack::PopAndDestroy(); |
|
1346 CleanupStack::Pop(); |
|
1347 CleanupStack::PushL( elements); |
|
1348 } |
|
1349 |
|
1350 if ( elements) size += elements->Length(); |
|
1351 |
|
1352 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
1353 |
|
1354 TPtr8 ptr = hbuf->Des(); |
|
1355 |
|
1356 ptr.Append('<'); |
|
1357 ptr.Append(PolicyLanguage::Rule::Rule[ aLanguage]); |
|
1358 ptr.Append(' '); |
|
1359 ptr.Append(PolicyLanguage::Rule::RuleId[ aLanguage]); |
|
1360 ptr.Append(_L8("=\"")); |
|
1361 ptr.Append( ruleId); |
|
1362 ptr.Append(_L8("\" ")); |
|
1363 ptr.Append(PolicyLanguage::Rule::Effect[ aLanguage]); |
|
1364 ptr.Append(_L8("=\"")); |
|
1365 ptr.Append( effect); |
|
1366 ptr.Append(_L8("\">")); |
|
1367 if ( elements) ptr.Append(*elements); |
|
1368 ptr.Append(_L8("</")); |
|
1369 ptr.Append(PolicyLanguage::Rule::Rule[ aLanguage]); |
|
1370 ptr.Append('>'); |
|
1371 |
|
1372 CleanupStack::Pop(); |
|
1373 CleanupStack::PopAndDestroy(); |
|
1374 |
|
1375 reserver.Release(); |
|
1376 |
|
1377 return hbuf; |
|
1378 } |
|
1379 |
|
1380 |
|
1381 // ----------------------------------------------------------------------------- |
|
1382 // CRule::AddIdElementL |
|
1383 // ----------------------------------------------------------------------------- |
|
1384 // |
|
1385 const TDesC8& CRule::EffectValue() |
|
1386 { |
|
1387 if ( iEffect) |
|
1388 { |
|
1389 return *iEffect; |
|
1390 } |
|
1391 |
|
1392 return KNullDesC8; |
|
1393 } |
|
1394 |
|
1395 // ----------------------------------------------------------------------------- |
|
1396 // CRule::SetRuleIdL |
|
1397 // ----------------------------------------------------------------------------- |
|
1398 // |
|
1399 void CRule::SetRuleIdL( const TDesC8& aName) |
|
1400 { |
|
1401 delete iExternalId; |
|
1402 iExternalId = NULL; |
|
1403 iRuleId = iExternalId = aName.AllocL(); |
|
1404 } |
|
1405 |
|
1406 |
|
1407 // ----------------------------------------------------------------------------- |
|
1408 // CRule::SetEffectL |
|
1409 // ----------------------------------------------------------------------------- |
|
1410 // |
|
1411 void CRule::SetEffectL( const TDesC8& aEffect) |
|
1412 { |
|
1413 delete iEffect; |
|
1414 iEffect = NULL; |
|
1415 iEffect = aEffect.AllocL(); |
|
1416 |
|
1417 } |
|
1418 |
|
1419 |
|
1420 |
|
1421 // ----------------------------------------------------------------------------- |
|
1422 // CRule::GetTarget |
|
1423 // ----------------------------------------------------------------------------- |
|
1424 // |
|
1425 |
|
1426 CTarget* CRule::GetTarget() |
|
1427 { |
|
1428 return (CTarget*) iTarget; |
|
1429 } |
|
1430 |
|
1431 |
|
1432 // ----------------------------------------------------------------------------- |
|
1433 // CRule::AddIdElementL |
|
1434 // ----------------------------------------------------------------------------- |
|
1435 // |
|
1436 |
|
1437 |
|
1438 void CRule::AddIdElementL( CElementBase * aElement) |
|
1439 { |
|
1440 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1441 |
|
1442 if ( aElement->ElementType() == ETarget ) |
|
1443 { |
|
1444 iTarget = aElement; |
|
1445 } |
|
1446 else |
|
1447 if ( aElement->ElementType() == ECondition ) |
|
1448 { |
|
1449 iCondition = aElement; |
|
1450 } |
|
1451 else |
|
1452 if ( aElement->ElementType() == EDescription ) |
|
1453 { |
|
1454 iDescription = aElement; |
|
1455 } |
|
1456 |
|
1457 AddToElementListL( aElement, EFalse); |
|
1458 } |
|
1459 |
|
1460 // ----------------------------------------------------------------------------- |
|
1461 // CRule::AddAttributeL |
|
1462 // ----------------------------------------------------------------------------- |
|
1463 // |
|
1464 |
|
1465 |
|
1466 void CRule::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
1467 { |
|
1468 if ( aName == PolicyLanguage::NativeLanguage::Rule::RuleId) |
|
1469 { |
|
1470 aParser->HandleErrorL( iRuleId , ParserErrors::UnexpectedAttribute, aName); |
|
1471 iRuleId = aValue.AllocL(); |
|
1472 iExternalId = iRuleId; |
|
1473 aParser->CheckExternalIdL( iExternalId); |
|
1474 } |
|
1475 else |
|
1476 if ( aName == PolicyLanguage::NativeLanguage::Rule::Effect) |
|
1477 { |
|
1478 aParser->HandleErrorL( iEffect, ParserErrors::UnexpectedAttribute, aName); |
|
1479 aParser->CheckEffectL( aValue); |
|
1480 iEffect = aValue.AllocL(); |
|
1481 } |
|
1482 else |
|
1483 { |
|
1484 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName ); |
|
1485 } |
|
1486 } |
|
1487 |
|
1488 // ----------------------------------------------------------------------------- |
|
1489 // CRule::AddElementL |
|
1490 // ----------------------------------------------------------------------------- |
|
1491 // |
|
1492 |
|
1493 |
|
1494 void CRule::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
1495 { |
|
1496 if ( aElement->ElementType() == ETarget ) |
|
1497 { |
|
1498 if ( aParser ) |
|
1499 { |
|
1500 aParser->HandleErrorL( iTarget, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1501 } |
|
1502 |
|
1503 AddToElementListL( aElement, ETrue); |
|
1504 iTarget = aElement; |
|
1505 } else |
|
1506 if ( aElement->ElementType() == EDescription ) |
|
1507 { |
|
1508 aParser->HandleErrorL( iDescription, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1509 AddToElementListL( aElement, ETrue); |
|
1510 iDescription = aElement; |
|
1511 } else |
|
1512 if ( aElement->ElementType() == ECondition ) |
|
1513 { |
|
1514 aParser->HandleErrorL( iCondition, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1515 AddToElementListL( aElement, ETrue); |
|
1516 iCondition = aElement; |
|
1517 } else |
|
1518 { |
|
1519 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1520 } |
|
1521 }; |
|
1522 |
|
1523 // ----------------------------------------------------------------------------- |
|
1524 // CRule::ValidElement |
|
1525 // ----------------------------------------------------------------------------- |
|
1526 // |
|
1527 |
|
1528 |
|
1529 TBool CRule::ValidElement() |
|
1530 { |
|
1531 return iEffect && iRuleId && iTarget; |
|
1532 } |
|
1533 |
|
1534 // ----------------------------------------------------------------------------- |
|
1535 // CRule::MatchL |
|
1536 // ----------------------------------------------------------------------------- |
|
1537 // |
|
1538 |
|
1539 |
|
1540 TMatchResponse CRule::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
1541 { |
|
1542 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
1543 |
|
1544 __ASSERT_ALWAYS ( iTarget, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
1545 |
|
1546 //check rule target match |
|
1547 TElementReserver targetReserver( iTarget); |
|
1548 CPolicyStorage::PolicyStorage()->CheckElementL( iTarget); |
|
1549 RDEBUG8_2("PolicyEngineServer: %S match evaluation started", ExternalId()); |
|
1550 TMatchResponse response = iTarget->MatchL( aPolicyProcessor); |
|
1551 |
|
1552 //if match evaluated effect of rule is checked otherwise result is NOT APPLICABLE |
|
1553 if ( response == EMatch) |
|
1554 { |
|
1555 RDEBUG8_2("PolicyEngineServer: %S evaluated: MATCH", ExternalId()); |
|
1556 |
|
1557 //effect if deny or permit, in effect case also condition is evaluated |
|
1558 if ( *iEffect == PolicyLanguage::Rule::Permit[ ENative]) |
|
1559 { |
|
1560 RDEBUG8_2("PolicyEngineServer: %S, Effect == PERMIT", ExternalId()); |
|
1561 response = EPermit; |
|
1562 |
|
1563 if ( iCondition) |
|
1564 { |
|
1565 //condition exists |
|
1566 RDEBUG8_2("PolicyEngineServer: %S contains condition", ExternalId()); |
|
1567 |
|
1568 //avaluated condition value (true or false) |
|
1569 TElementReserver targetReserver( iCondition); |
|
1570 CPolicyStorage::PolicyStorage()->CheckElementL( iCondition); |
|
1571 TMatchResponse condResp = ((CCondition*)iCondition)->ConditionValueL( aPolicyProcessor); |
|
1572 targetReserver.Release(); |
|
1573 |
|
1574 //condition == unmatch -> conditition is not valid -> result will be NOT APPLICABLE |
|
1575 if ( condResp == EUnMatch) |
|
1576 { |
|
1577 RDEBUG8_2("PolicyEngineServer: %S, condition evaluated -> NOT APPLICABLE", ExternalId()); |
|
1578 response = ENotApplicable; |
|
1579 } |
|
1580 else if ( condResp == EIndeterminate) |
|
1581 { |
|
1582 //error in condition evaluation -> result will be INDETERMINATE |
|
1583 RDEBUG8_2("PolicyEngineServer: %S, condition evaluated -> INDETERMINATE", ExternalId()); |
|
1584 response = EIndeterminate; |
|
1585 } |
|
1586 else |
|
1587 { |
|
1588 //other result is permit.... |
|
1589 response = EPermit; |
|
1590 RDEBUG8_2("PolicyEngineServer: %S, condition evaluated -> PERMIT", ExternalId()); |
|
1591 } |
|
1592 } |
|
1593 } |
|
1594 else |
|
1595 { |
|
1596 //in DENY is clear -> result will be DENY |
|
1597 RDEBUG8_2("PolicyEngineServer: %S, Effect == DENY", ExternalId()); |
|
1598 response = EDeny; |
|
1599 } |
|
1600 } |
|
1601 else |
|
1602 { |
|
1603 RDEBUG8_2("PolicyEngineServer: %S -> NOT APPLICABLE", ExternalId()); |
|
1604 response = ENotApplicable; |
|
1605 } |
|
1606 |
|
1607 RDEBUG8_2("PolicyEngineServer: %S match evaluation finished", ExternalId()); |
|
1608 targetReserver.Release(); |
|
1609 return response; |
|
1610 |
|
1611 #endif// __POLICY_BASE_CREATOR_TOOL |
|
1612 } |
|
1613 |
|
1614 |
|
1615 // ----------------------------------------------------------------------------- |
|
1616 // CRule::Effect |
|
1617 // ----------------------------------------------------------------------------- |
|
1618 // |
|
1619 |
|
1620 |
|
1621 TMatchResponse CRule::Effect() |
|
1622 { |
|
1623 TMatchResponse response; |
|
1624 if ( *iEffect == PolicyLanguage::Rule::Permit[ ENative]) |
|
1625 { |
|
1626 response = EPermit; |
|
1627 } |
|
1628 else |
|
1629 { |
|
1630 response = EDeny; |
|
1631 } |
|
1632 |
|
1633 return response; |
|
1634 } |
|
1635 |
|
1636 // ----------------------------------------------------------------------------- |
|
1637 // CTarget::CTarget |
|
1638 // ----------------------------------------------------------------------------- |
|
1639 // |
|
1640 |
|
1641 |
|
1642 CTarget::CTarget() |
|
1643 { |
|
1644 iElementType = ETarget; |
|
1645 iElementName.Set( PolicyLanguage::NativeLanguage::Rule::Target); |
|
1646 |
|
1647 iSaveType = ESubElement; |
|
1648 } |
|
1649 |
|
1650 // ----------------------------------------------------------------------------- |
|
1651 // CTarget::~CTarget |
|
1652 // ----------------------------------------------------------------------------- |
|
1653 // |
|
1654 |
|
1655 CTarget::~CTarget() |
|
1656 { |
|
1657 } |
|
1658 |
|
1659 // ----------------------------------------------------------------------------- |
|
1660 // CTarget::NewL |
|
1661 // ----------------------------------------------------------------------------- |
|
1662 // |
|
1663 |
|
1664 CTarget * CTarget::NewL() |
|
1665 { |
|
1666 return new (ELeave) CTarget(); |
|
1667 } |
|
1668 |
|
1669 |
|
1670 // ----------------------------------------------------------------------------- |
|
1671 // CTarget::GetMatchContainers |
|
1672 // ----------------------------------------------------------------------------- |
|
1673 // |
|
1674 |
|
1675 void CTarget::GetMatchContainersL( RMatchObjectArray& aMatchContainer ) |
|
1676 { |
|
1677 if ( iSubjects) |
|
1678 { |
|
1679 ((CItemContainer*)iSubjects)->GetMatchContainersL( aMatchContainer); |
|
1680 } |
|
1681 if ( iResources) |
|
1682 { |
|
1683 ((CItemContainer*)iResources)->GetMatchContainersL( aMatchContainer); |
|
1684 } |
|
1685 if ( iActions) |
|
1686 { |
|
1687 ((CItemContainer*)iActions)->GetMatchContainersL( aMatchContainer); |
|
1688 } |
|
1689 if ( iEnvironments) |
|
1690 { |
|
1691 ((CItemContainer*)iEnvironments)->GetMatchContainersL( aMatchContainer); |
|
1692 } |
|
1693 } |
|
1694 |
|
1695 |
|
1696 |
|
1697 // ----------------------------------------------------------------------------- |
|
1698 // CTarget::IdentificateType |
|
1699 // ----------------------------------------------------------------------------- |
|
1700 // |
|
1701 |
|
1702 TBool CTarget::IdentificateType( const TDesC8& aElementName) |
|
1703 { |
|
1704 return ( aElementName == PolicyLanguage::NativeLanguage::Rule::Target); |
|
1705 } |
|
1706 |
|
1707 // ----------------------------------------------------------------------------- |
|
1708 // CTarget::DecodeElementL |
|
1709 // ----------------------------------------------------------------------------- |
|
1710 // |
|
1711 |
|
1712 HBufC8 * CTarget::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) |
|
1713 { |
|
1714 RDEBUG("PolicyEngineServer: Decode Target element"); |
|
1715 |
|
1716 TPtrC8 ptr; |
|
1717 ptr.Set( PolicyLanguage::Rule::Target[ aLanguage]); |
|
1718 |
|
1719 if ( !ElementCount()) |
|
1720 { |
|
1721 return ElementHelper::DecodeEmptyElement( ptr); |
|
1722 } |
|
1723 |
|
1724 CheckAllElementsL(); |
|
1725 TElementReserver reserver( Container()); |
|
1726 |
|
1727 _LIT8( DecodeFormat, "<%S>%S</%S>"); |
|
1728 |
|
1729 TInt size(15); |
|
1730 size += 2 * ptr.Length(); |
|
1731 |
|
1732 HBufC8 * elements = NULL; |
|
1733 CleanupStack::PushL( elements); |
|
1734 |
|
1735 for ( TInt i(0); i < ElementCount(); i++) |
|
1736 { |
|
1737 CElementBase * element = Element(i); |
|
1738 |
|
1739 HBufC8 * decode = DecodeElementOrIdL( aLanguage, element, aMode); |
|
1740 |
|
1741 CleanupStack::PushL( decode); |
|
1742 |
|
1743 if ( elements) |
|
1744 { |
|
1745 elements = elements->ReAlloc( elements->Length() + decode->Length() + 10);; |
|
1746 } |
|
1747 else |
|
1748 { |
|
1749 elements = HBufC8::NewL( decode->Length() + 10); |
|
1750 } |
|
1751 |
|
1752 elements->Des().Append( *decode); |
|
1753 CleanupStack::PopAndDestroy(); |
|
1754 CleanupStack::Pop(); |
|
1755 CleanupStack::PushL( elements); |
|
1756 } |
|
1757 |
|
1758 if (elements) |
|
1759 { |
|
1760 size += elements->Length(); |
|
1761 } |
|
1762 |
|
1763 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
1764 |
|
1765 hbuf->Des().Format( DecodeFormat, &ptr, elements, &ptr); |
|
1766 |
|
1767 CleanupStack::Pop(); |
|
1768 CleanupStack::PopAndDestroy(); |
|
1769 |
|
1770 reserver.Release(); |
|
1771 |
|
1772 return hbuf; |
|
1773 } |
|
1774 |
|
1775 // ----------------------------------------------------------------------------- |
|
1776 // CTarget::AddIdElementL |
|
1777 // ----------------------------------------------------------------------------- |
|
1778 // |
|
1779 |
|
1780 void CTarget::AddIdElementL( CElementBase * aElement) |
|
1781 { |
|
1782 if ( aElement->ElementType() == ESubjects ) |
|
1783 { |
|
1784 iSubjects = aElement; |
|
1785 } |
|
1786 else |
|
1787 if ( aElement->ElementType() == EActions ) |
|
1788 { |
|
1789 iActions = aElement; |
|
1790 } |
|
1791 else |
|
1792 if ( aElement->ElementType() == EResources ) |
|
1793 { |
|
1794 iResources = aElement; |
|
1795 } |
|
1796 else |
|
1797 if ( aElement->ElementType() == EEnvironments ) |
|
1798 { |
|
1799 iEnvironments = aElement; |
|
1800 } |
|
1801 |
|
1802 AddToElementListL( aElement, EFalse); |
|
1803 } |
|
1804 |
|
1805 // ----------------------------------------------------------------------------- |
|
1806 // CTarget::ValidElement() |
|
1807 // ----------------------------------------------------------------------------- |
|
1808 // |
|
1809 |
|
1810 TBool CTarget::ValidElement() |
|
1811 { |
|
1812 //Target is allways valid |
|
1813 return ETrue;//(iSubjects || iActions || iResources || iEnvironments); |
|
1814 } |
|
1815 |
|
1816 |
|
1817 // ----------------------------------------------------------------------------- |
|
1818 // CTarget::MatchL() |
|
1819 // ----------------------------------------------------------------------------- |
|
1820 // |
|
1821 |
|
1822 |
|
1823 TMatchResponse CTarget::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
1824 { |
|
1825 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
1826 |
|
1827 TMatchResponse response( ENotApplicable); |
|
1828 TBool atLeastOneMatchExecuted = EFalse; |
|
1829 CPolicyStorage * storage = CPolicyStorage::PolicyStorage(); |
|
1830 |
|
1831 //check all matches... |
|
1832 //if any subject exist, check match |
|
1833 if ( iSubjects ) |
|
1834 { |
|
1835 TElementReserver element( iSubjects); |
|
1836 storage->CheckElementL( iSubjects); |
|
1837 response = iSubjects->MatchL( aPolicyProcessor); |
|
1838 atLeastOneMatchExecuted = ETrue; |
|
1839 element.Release(); |
|
1840 } |
|
1841 |
|
1842 //if not unmatch from previous elements, and any actions exist, check match |
|
1843 if ( response != EUnMatch && iActions) |
|
1844 { |
|
1845 TElementReserver element( iActions); |
|
1846 storage->CheckElementL( iActions); |
|
1847 response = iActions->MatchL( aPolicyProcessor); |
|
1848 atLeastOneMatchExecuted = ETrue; |
|
1849 element.Release(); |
|
1850 } |
|
1851 |
|
1852 //if not unmatch from previous elements, and any resources exist, check match |
|
1853 if ( response != EUnMatch && iResources) |
|
1854 { |
|
1855 TElementReserver element( iResources); |
|
1856 storage->CheckElementL( iResources); |
|
1857 response = iResources->MatchL( aPolicyProcessor); |
|
1858 atLeastOneMatchExecuted = ETrue; |
|
1859 element.Release(); |
|
1860 } |
|
1861 |
|
1862 //if not unmatch from previous elements, and any environments exist, check match |
|
1863 if ( response != EUnMatch && iEnvironments) |
|
1864 { |
|
1865 TElementReserver element( iEnvironments); |
|
1866 storage->CheckElementL( iEnvironments); |
|
1867 response = iEnvironments->MatchL( aPolicyProcessor); |
|
1868 atLeastOneMatchExecuted = ETrue; |
|
1869 element.Release(); |
|
1870 } |
|
1871 |
|
1872 //if target doesn't have any objects, it is applicable to any object... |
|
1873 if ( !atLeastOneMatchExecuted ) |
|
1874 { |
|
1875 response = EMatch; |
|
1876 } |
|
1877 |
|
1878 if ( response == ENotApplicable) |
|
1879 { |
|
1880 response = EUnMatch; |
|
1881 } |
|
1882 |
|
1883 return response; |
|
1884 |
|
1885 #endif //__POLICY_BASE_CREATOR_TOOL |
|
1886 } |
|
1887 |
|
1888 |
|
1889 // ----------------------------------------------------------------------------- |
|
1890 // CTarget::AddElementL() |
|
1891 // ----------------------------------------------------------------------------- |
|
1892 // |
|
1893 |
|
1894 void CTarget::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
1895 { |
|
1896 //check is element already exist and add it correct place |
|
1897 |
|
1898 if ( aElement->ElementType() == ESubjects ) |
|
1899 { |
|
1900 if ( aParser ) |
|
1901 { |
|
1902 aParser->HandleErrorL( iSubjects, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1903 } |
|
1904 iSubjects = aElement; |
|
1905 } |
|
1906 else |
|
1907 if ( aElement->ElementType() == EActions ) |
|
1908 { |
|
1909 if ( aParser ) |
|
1910 { |
|
1911 aParser->HandleErrorL( iActions, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1912 } |
|
1913 iActions = aElement; |
|
1914 } |
|
1915 else |
|
1916 if ( aElement->ElementType() == EResources ) |
|
1917 { |
|
1918 if ( aParser ) |
|
1919 { |
|
1920 aParser->HandleErrorL( iResources, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1921 } |
|
1922 iResources = aElement; |
|
1923 } |
|
1924 else |
|
1925 if ( aElement->ElementType() == EEnvironments ) |
|
1926 { |
|
1927 if ( aParser ) |
|
1928 { |
|
1929 aParser->HandleErrorL( iEnvironments, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1930 } |
|
1931 iEnvironments = aElement; |
|
1932 } |
|
1933 else |
|
1934 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
1935 |
|
1936 //add element also to element list |
|
1937 AddToElementListL( aElement, ETrue); |
|
1938 } |
|
1939 |
|
1940 // ----------------------------------------------------------------------------- |
|
1941 // CItemContainer::CItemContainer() |
|
1942 // ----------------------------------------------------------------------------- |
|
1943 // |
|
1944 |
|
1945 CItemContainer::CItemContainer() |
|
1946 { |
|
1947 |
|
1948 } |
|
1949 |
|
1950 // ----------------------------------------------------------------------------- |
|
1951 // CItemContainer::~CItemContainer() |
|
1952 // ----------------------------------------------------------------------------- |
|
1953 // |
|
1954 |
|
1955 |
|
1956 CItemContainer::~CItemContainer() |
|
1957 { |
|
1958 |
|
1959 } |
|
1960 |
|
1961 // ----------------------------------------------------------------------------- |
|
1962 // CItemContainer::DecodeElementL |
|
1963 // ----------------------------------------------------------------------------- |
|
1964 // |
|
1965 |
|
1966 HBufC8 * CItemContainer::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode ) |
|
1967 { |
|
1968 RDEBUG("PolicyEngineServer: Decode ItemContainer element"); |
|
1969 |
|
1970 |
|
1971 _LIT8( DecodeFormat, "<%S>%S</%S>"); |
|
1972 |
|
1973 TInt size(15); |
|
1974 |
|
1975 TPtrC8 ptr; |
|
1976 if ( iElementType == ESubject ) |
|
1977 ptr.Set( PolicyLanguage::MatchContainers::Subject[ aLanguage]); |
|
1978 else if ( iElementType == EAction ) |
|
1979 ptr.Set( PolicyLanguage::MatchContainers::Action[ aLanguage]); |
|
1980 else if ( iElementType == EResource ) |
|
1981 ptr.Set( PolicyLanguage::MatchContainers::Resource[ aLanguage]); |
|
1982 else if ( iElementType == EEnvironment ) |
|
1983 ptr.Set( PolicyLanguage::MatchContainers::Environment[ aLanguage]); |
|
1984 else if ( iElementType == ESubjects ) |
|
1985 ptr.Set( PolicyLanguage::MatchContainers::Subjects[ aLanguage]); |
|
1986 else if ( iElementType == EActions ) |
|
1987 ptr.Set( PolicyLanguage::MatchContainers::Actions[ aLanguage]); |
|
1988 else if ( iElementType == EResources ) |
|
1989 ptr.Set( PolicyLanguage::MatchContainers::Resources[ aLanguage]); |
|
1990 else |
|
1991 ptr.Set( PolicyLanguage::MatchContainers::Environments[ aLanguage]); |
|
1992 |
|
1993 if ( !ElementCount()) |
|
1994 { |
|
1995 return ElementHelper::DecodeEmptyElement( ptr); |
|
1996 } |
|
1997 |
|
1998 CheckAllElementsL(); |
|
1999 TElementReserver reserver( Container()); |
|
2000 |
|
2001 size += 2 * ptr.Length(); |
|
2002 |
|
2003 HBufC8 * elements = NULL; |
|
2004 CleanupStack::PushL( elements); |
|
2005 |
|
2006 for ( TInt i(0); i < ElementCount(); i++) |
|
2007 { |
|
2008 CElementBase * element = Element(i); |
|
2009 |
|
2010 HBufC8 * decode = DecodeElementOrIdL( aLanguage, element, aMode); |
|
2011 |
|
2012 CleanupStack::PushL( decode); |
|
2013 |
|
2014 if ( elements) |
|
2015 { |
|
2016 elements = elements->ReAlloc( elements->Length() + decode->Length() + 10);; |
|
2017 } |
|
2018 else |
|
2019 { |
|
2020 elements = HBufC8::NewL( decode->Length() + 10); |
|
2021 } |
|
2022 |
|
2023 elements->Des().Append( *decode); |
|
2024 |
|
2025 CleanupStack::PopAndDestroy(); |
|
2026 CleanupStack::Pop(); |
|
2027 CleanupStack::PushL( elements); |
|
2028 } |
|
2029 |
|
2030 if (elements) |
|
2031 { |
|
2032 size += elements->Length(); |
|
2033 } |
|
2034 |
|
2035 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
2036 |
|
2037 hbuf->Des().Format( DecodeFormat, &ptr, elements, &ptr); |
|
2038 |
|
2039 CleanupStack::Pop( hbuf); |
|
2040 CleanupStack::PopAndDestroy(); |
|
2041 |
|
2042 reserver.Release(); |
|
2043 |
|
2044 return hbuf; |
|
2045 } |
|
2046 |
|
2047 // ----------------------------------------------------------------------------- |
|
2048 // CItemContainer::GetMatchContainersL |
|
2049 // ----------------------------------------------------------------------------- |
|
2050 // |
|
2051 |
|
2052 void CItemContainer::GetMatchContainersL( RMatchObjectArray& aMatchContainer ) |
|
2053 { |
|
2054 for ( TInt i(0); i < ElementCount(); i++) |
|
2055 { |
|
2056 CElementBase * element = Element(i); |
|
2057 |
|
2058 __ASSERT_ALWAYS ( element, User::Panic( Panics::PolicyExecutionPanic, KErrCorrupt)); |
|
2059 |
|
2060 TNativeElementTypes elementType = element->ElementType(); |
|
2061 |
|
2062 if ( elementType == ESubjectMatch || |
|
2063 elementType == EResourceMatch || |
|
2064 elementType == EActionMatch || |
|
2065 elementType == EEnvironmentMatch ) |
|
2066 { |
|
2067 aMatchContainer.AppendL((CMatchObject*)element); |
|
2068 } |
|
2069 else if ( elementType == ESubject || |
|
2070 elementType == EResource || |
|
2071 elementType == EAction || |
|
2072 elementType == EEnvironment ) |
|
2073 { |
|
2074 ((CItemContainer*)element)->GetMatchContainersL(aMatchContainer); |
|
2075 } |
|
2076 } |
|
2077 } |
|
2078 |
|
2079 |
|
2080 // ----------------------------------------------------------------------------- |
|
2081 // CItemContainer::ValidElement |
|
2082 // ----------------------------------------------------------------------------- |
|
2083 // |
|
2084 |
|
2085 TBool CItemContainer::ValidElement() |
|
2086 { |
|
2087 //empty elements are possible |
|
2088 return ETrue; //( ElementCount() > 0); |
|
2089 } |
|
2090 |
|
2091 // ----------------------------------------------------------------------------- |
|
2092 // CItemContainer::MatchL |
|
2093 // ----------------------------------------------------------------------------- |
|
2094 // |
|
2095 |
|
2096 |
|
2097 TMatchResponse CItemContainer::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
2098 { |
|
2099 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
2100 |
|
2101 //evaluate subject (or resouce...) components or subjectmatch (or resourcematch) components |
|
2102 for ( TInt i(0); i < ElementCount(); i++) |
|
2103 { |
|
2104 //reserve and check element |
|
2105 CElementBase * element = Element(i); |
|
2106 TElementReserver elementReserver( element); |
|
2107 CPolicyStorage::PolicyStorage()->CheckElementL( element); |
|
2108 |
|
2109 //avaluate match |
|
2110 TMatchResponse response = element->MatchL( aPolicyProcessor); |
|
2111 |
|
2112 elementReserver.Release(); |
|
2113 |
|
2114 //if indeterminate -> result will be indeterminate |
|
2115 if ( response == EIndeterminate ) return EIndeterminate; |
|
2116 |
|
2117 |
|
2118 if ( response == EMatch ) |
|
2119 { |
|
2120 //In OR-(subject) case one match is enough to evaluate result -> EMatch |
|
2121 if ( iBooleanType == EOrBoolean ) |
|
2122 { |
|
2123 return EMatch; |
|
2124 } |
|
2125 } |
|
2126 else |
|
2127 { |
|
2128 //In AND-(subjectmatch) case one unmatch is enough to evaluate result -> EUnMatch |
|
2129 if ( iBooleanType == EAndBoolean ) |
|
2130 { |
|
2131 return EUnMatch; |
|
2132 } |
|
2133 } |
|
2134 } |
|
2135 |
|
2136 //if this point is reached, match evaluation bases on component type (OR or AND) |
|
2137 //in OR cases it means that none of matched found |
|
2138 //in AND cases it means that none of unmatches founb |
|
2139 TMatchResponse response( EMatch); |
|
2140 if ( iBooleanType == EOrBoolean) |
|
2141 { |
|
2142 response = EUnMatch; |
|
2143 } |
|
2144 |
|
2145 return response; |
|
2146 |
|
2147 #endif // __POLICY_BASE_CREATOR_TOOL |
|
2148 } |
|
2149 |
|
2150 |
|
2151 // ----------------------------------------------------------------------------- |
|
2152 // CItemContainer:: |
|
2153 // ----------------------------------------------------------------------------- |
|
2154 // |
|
2155 |
|
2156 void CItemContainer::AddIdElementL( CElementBase * aElement) |
|
2157 { |
|
2158 AddToElementListL( aElement, EFalse); |
|
2159 } |
|
2160 |
|
2161 // ----------------------------------------------------------------------------- |
|
2162 // CItemContainer:: |
|
2163 // ----------------------------------------------------------------------------- |
|
2164 // |
|
2165 |
|
2166 void CItemContainer::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
2167 { |
|
2168 if ( aElement->ElementType() == iAllowedType) |
|
2169 AddToElementListL( aElement, ETrue); |
|
2170 else |
|
2171 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
2172 } |
|
2173 |
|
2174 // ----------------------------------------------------------------------------- |
|
2175 // CSubjects:: |
|
2176 // ----------------------------------------------------------------------------- |
|
2177 // |
|
2178 |
|
2179 CSubjects::CSubjects() |
|
2180 { |
|
2181 iElementType = ESubjects; |
|
2182 iAllowedType = ESubject; |
|
2183 iBooleanType = EOrBoolean; |
|
2184 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Subjects); |
|
2185 |
|
2186 iSaveType = ESubElement; |
|
2187 } |
|
2188 |
|
2189 // ----------------------------------------------------------------------------- |
|
2190 // CSubjects:: |
|
2191 // ----------------------------------------------------------------------------- |
|
2192 // |
|
2193 |
|
2194 CSubjects::~CSubjects() |
|
2195 { |
|
2196 } |
|
2197 |
|
2198 // ----------------------------------------------------------------------------- |
|
2199 // CSubjects:: |
|
2200 // ----------------------------------------------------------------------------- |
|
2201 // |
|
2202 |
|
2203 CSubjects * CSubjects::NewL() |
|
2204 { |
|
2205 return new (ELeave) CSubjects(); |
|
2206 } |
|
2207 |
|
2208 // ----------------------------------------------------------------------------- |
|
2209 // CSubjects:: |
|
2210 // ----------------------------------------------------------------------------- |
|
2211 // |
|
2212 |
|
2213 TBool CSubjects::IdentificateType( const TDesC8& aElementName) |
|
2214 { |
|
2215 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Subjects); |
|
2216 } |
|
2217 |
|
2218 // ----------------------------------------------------------------------------- |
|
2219 // CSubject:: |
|
2220 // ----------------------------------------------------------------------------- |
|
2221 // |
|
2222 |
|
2223 CSubject::CSubject() |
|
2224 { |
|
2225 iElementType = ESubject; |
|
2226 iAllowedType = ESubjectMatch; |
|
2227 iBooleanType = EAndBoolean; |
|
2228 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Subject); |
|
2229 |
|
2230 iSaveType = ESubElement; |
|
2231 } |
|
2232 |
|
2233 // ----------------------------------------------------------------------------- |
|
2234 // CSubject:: |
|
2235 // ----------------------------------------------------------------------------- |
|
2236 // |
|
2237 |
|
2238 |
|
2239 CSubject::~CSubject() |
|
2240 { |
|
2241 } |
|
2242 |
|
2243 // ----------------------------------------------------------------------------- |
|
2244 // CSubject:: |
|
2245 // ----------------------------------------------------------------------------- |
|
2246 // |
|
2247 |
|
2248 |
|
2249 CSubject * CSubject::NewL() |
|
2250 { |
|
2251 return new (ELeave) CSubject(); |
|
2252 } |
|
2253 |
|
2254 // ----------------------------------------------------------------------------- |
|
2255 // CSubject:: |
|
2256 // ----------------------------------------------------------------------------- |
|
2257 // |
|
2258 |
|
2259 |
|
2260 TBool CSubject::IdentificateType( const TDesC8& aElementName) |
|
2261 { |
|
2262 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Subject); |
|
2263 } |
|
2264 |
|
2265 // ----------------------------------------------------------------------------- |
|
2266 // CAction:: |
|
2267 // ----------------------------------------------------------------------------- |
|
2268 // |
|
2269 |
|
2270 |
|
2271 CAction::CAction() |
|
2272 { |
|
2273 iElementType = EAction; |
|
2274 iAllowedType = EActionMatch; |
|
2275 iBooleanType = EAndBoolean; |
|
2276 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Action); |
|
2277 |
|
2278 iSaveType = ESubElement; |
|
2279 } |
|
2280 |
|
2281 // ----------------------------------------------------------------------------- |
|
2282 // CAction:: |
|
2283 // ----------------------------------------------------------------------------- |
|
2284 // |
|
2285 |
|
2286 |
|
2287 CAction::~CAction() |
|
2288 { |
|
2289 } |
|
2290 |
|
2291 // ----------------------------------------------------------------------------- |
|
2292 // CAction:: |
|
2293 // ----------------------------------------------------------------------------- |
|
2294 // |
|
2295 |
|
2296 CElementBase * CAction::NewL() |
|
2297 { |
|
2298 return new (ELeave) CAction(); |
|
2299 } |
|
2300 |
|
2301 // ----------------------------------------------------------------------------- |
|
2302 // CAction:: |
|
2303 // ----------------------------------------------------------------------------- |
|
2304 // |
|
2305 |
|
2306 TBool CAction::IdentificateType( const TDesC8& aElementName) |
|
2307 { |
|
2308 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Action); |
|
2309 } |
|
2310 |
|
2311 // ----------------------------------------------------------------------------- |
|
2312 // CActions:: |
|
2313 // ----------------------------------------------------------------------------- |
|
2314 // |
|
2315 |
|
2316 |
|
2317 CActions::CActions() |
|
2318 { |
|
2319 iElementType = EActions; |
|
2320 iAllowedType = EAction; |
|
2321 iBooleanType = EOrBoolean; |
|
2322 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Actions); |
|
2323 |
|
2324 iSaveType = ESubElement; |
|
2325 } |
|
2326 |
|
2327 // ----------------------------------------------------------------------------- |
|
2328 // CActions:: |
|
2329 // ----------------------------------------------------------------------------- |
|
2330 // |
|
2331 |
|
2332 |
|
2333 CActions::~CActions() |
|
2334 { |
|
2335 } |
|
2336 |
|
2337 // ----------------------------------------------------------------------------- |
|
2338 // CActions:: |
|
2339 // ----------------------------------------------------------------------------- |
|
2340 // |
|
2341 |
|
2342 |
|
2343 CElementBase * CActions::NewL() |
|
2344 { |
|
2345 return new (ELeave) CActions(); |
|
2346 } |
|
2347 |
|
2348 // ----------------------------------------------------------------------------- |
|
2349 // CActions:: |
|
2350 // ----------------------------------------------------------------------------- |
|
2351 // |
|
2352 |
|
2353 |
|
2354 TBool CActions::IdentificateType( const TDesC8& aElementName) |
|
2355 { |
|
2356 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Actions); |
|
2357 } |
|
2358 |
|
2359 // ----------------------------------------------------------------------------- |
|
2360 // CResource:: |
|
2361 // ----------------------------------------------------------------------------- |
|
2362 // |
|
2363 |
|
2364 |
|
2365 |
|
2366 CResource::CResource() |
|
2367 { |
|
2368 iElementType = EResource; |
|
2369 iAllowedType = EResourceMatch; |
|
2370 iBooleanType = EAndBoolean; |
|
2371 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Resource); |
|
2372 |
|
2373 iSaveType = ESubElement; |
|
2374 } |
|
2375 |
|
2376 // ----------------------------------------------------------------------------- |
|
2377 // CResource:: |
|
2378 // ----------------------------------------------------------------------------- |
|
2379 // |
|
2380 |
|
2381 |
|
2382 CResource::~CResource() |
|
2383 { |
|
2384 } |
|
2385 |
|
2386 // ----------------------------------------------------------------------------- |
|
2387 // CResource:: |
|
2388 // ----------------------------------------------------------------------------- |
|
2389 // |
|
2390 |
|
2391 |
|
2392 CElementBase * CResource::NewL() |
|
2393 { |
|
2394 return new (ELeave) CResource(); |
|
2395 } |
|
2396 |
|
2397 // ----------------------------------------------------------------------------- |
|
2398 // CResource::IdentificateType |
|
2399 // ----------------------------------------------------------------------------- |
|
2400 // |
|
2401 |
|
2402 |
|
2403 TBool CResource::IdentificateType( const TDesC8& aElementName) |
|
2404 { |
|
2405 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Resource); |
|
2406 } |
|
2407 |
|
2408 // ----------------------------------------------------------------------------- |
|
2409 // CResources::CResources |
|
2410 // ----------------------------------------------------------------------------- |
|
2411 // |
|
2412 |
|
2413 |
|
2414 CResources::CResources() |
|
2415 { |
|
2416 iElementType = EResources; |
|
2417 iAllowedType = EResource; |
|
2418 iBooleanType = EOrBoolean; |
|
2419 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Resources); |
|
2420 |
|
2421 iSaveType = ESubElement; |
|
2422 } |
|
2423 |
|
2424 |
|
2425 // ----------------------------------------------------------------------------- |
|
2426 // CResources:: |
|
2427 // ----------------------------------------------------------------------------- |
|
2428 // |
|
2429 |
|
2430 |
|
2431 CResources::~CResources() |
|
2432 { |
|
2433 } |
|
2434 // ----------------------------------------------------------------------------- |
|
2435 // CResources:: |
|
2436 // ----------------------------------------------------------------------------- |
|
2437 // |
|
2438 |
|
2439 |
|
2440 CElementBase * CResources::NewL() |
|
2441 { |
|
2442 return new (ELeave) CResources(); |
|
2443 } |
|
2444 |
|
2445 // ----------------------------------------------------------------------------- |
|
2446 // CResources:: |
|
2447 // ----------------------------------------------------------------------------- |
|
2448 // |
|
2449 |
|
2450 |
|
2451 TBool CResources::IdentificateType( const TDesC8& aElementName) |
|
2452 { |
|
2453 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Resources); |
|
2454 } |
|
2455 |
|
2456 // ----------------------------------------------------------------------------- |
|
2457 // CEnviroment:: |
|
2458 // ----------------------------------------------------------------------------- |
|
2459 // |
|
2460 |
|
2461 |
|
2462 CEnvironment::CEnvironment() |
|
2463 { |
|
2464 iElementType = EEnvironment; |
|
2465 iAllowedType = EEnvironmentMatch; |
|
2466 iBooleanType = EAndBoolean; |
|
2467 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Environment); |
|
2468 |
|
2469 iSaveType = ESubElement; |
|
2470 } |
|
2471 |
|
2472 // ----------------------------------------------------------------------------- |
|
2473 // CEnviroment:: |
|
2474 // ----------------------------------------------------------------------------- |
|
2475 // |
|
2476 |
|
2477 |
|
2478 CEnvironment::~CEnvironment() |
|
2479 { |
|
2480 } |
|
2481 |
|
2482 // ----------------------------------------------------------------------------- |
|
2483 // CEnviroment:: |
|
2484 // ----------------------------------------------------------------------------- |
|
2485 // |
|
2486 |
|
2487 |
|
2488 CElementBase * CEnvironment::NewL() |
|
2489 { |
|
2490 return new (ELeave) CEnvironment(); |
|
2491 } |
|
2492 |
|
2493 // ----------------------------------------------------------------------------- |
|
2494 // CEnviroment:: |
|
2495 // ----------------------------------------------------------------------------- |
|
2496 // |
|
2497 |
|
2498 TBool CEnvironment::IdentificateType( const TDesC8& aElementName) |
|
2499 { |
|
2500 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Environment); |
|
2501 } |
|
2502 |
|
2503 // ----------------------------------------------------------------------------- |
|
2504 // CEnviroments:: |
|
2505 // ----------------------------------------------------------------------------- |
|
2506 // |
|
2507 |
|
2508 |
|
2509 CEnvironments::CEnvironments() |
|
2510 { |
|
2511 iElementType = EEnvironments; |
|
2512 iAllowedType = EEnvironment; |
|
2513 iBooleanType = EOrBoolean; |
|
2514 iElementName.Set( PolicyLanguage::NativeLanguage::MatchContainers::Environments); |
|
2515 |
|
2516 } |
|
2517 |
|
2518 // ----------------------------------------------------------------------------- |
|
2519 // CEnviroments:: |
|
2520 // ----------------------------------------------------------------------------- |
|
2521 // |
|
2522 |
|
2523 |
|
2524 CEnvironments::~CEnvironments() |
|
2525 { |
|
2526 } |
|
2527 |
|
2528 // ----------------------------------------------------------------------------- |
|
2529 // CEnviroments:: |
|
2530 // ----------------------------------------------------------------------------- |
|
2531 // |
|
2532 |
|
2533 |
|
2534 CElementBase * CEnvironments::NewL() |
|
2535 { |
|
2536 return new (ELeave) CEnvironments(); |
|
2537 } |
|
2538 |
|
2539 // ----------------------------------------------------------------------------- |
|
2540 // CEnviroments:: |
|
2541 // ----------------------------------------------------------------------------- |
|
2542 // |
|
2543 |
|
2544 |
|
2545 TBool CEnvironments::IdentificateType( const TDesC8& aElementName) |
|
2546 { |
|
2547 return ( aElementName == PolicyLanguage::NativeLanguage::MatchContainers::Environments); |
|
2548 } |
|
2549 |
|
2550 // ----------------------------------------------------------------------------- |
|
2551 // CAttributeDesignator:: |
|
2552 // ----------------------------------------------------------------------------- |
|
2553 // |
|
2554 |
|
2555 |
|
2556 CAttributeDesignator::CAttributeDesignator() |
|
2557 : CElementBase() |
|
2558 { |
|
2559 iSaveType = ESubElement; |
|
2560 } |
|
2561 |
|
2562 // ----------------------------------------------------------------------------- |
|
2563 // CAttributeDesignator:: |
|
2564 // ----------------------------------------------------------------------------- |
|
2565 // |
|
2566 |
|
2567 |
|
2568 CAttributeDesignator::~CAttributeDesignator() |
|
2569 { |
|
2570 delete iAttributeId; |
|
2571 delete iDataType; |
|
2572 } |
|
2573 |
|
2574 // ----------------------------------------------------------------------------- |
|
2575 // CAttributeDesignator:: |
|
2576 // ----------------------------------------------------------------------------- |
|
2577 // |
|
2578 |
|
2579 |
|
2580 CElementBase * CAttributeDesignator::NewL( TNativeElementTypes aType) |
|
2581 { |
|
2582 CElementBase * designator = NULL; |
|
2583 |
|
2584 if ( aType == ESubjectAttributeDesignator) designator = CSubjectAttributeDesignator::NewL(); |
|
2585 else |
|
2586 if ( aType == EActionAttributeDesignator) designator = CActionAttributeDesignator::NewL(); |
|
2587 else |
|
2588 if ( aType == EResourceAttributeDesignator) designator = CResourceAttributeDesignator::NewL(); |
|
2589 else |
|
2590 if ( aType == EEnvironmentAttributeDesignator) designator = CEnvironmentAttributeDesignator::NewL(); |
|
2591 |
|
2592 return designator; |
|
2593 } |
|
2594 |
|
2595 // ----------------------------------------------------------------------------- |
|
2596 // CAttributeDesignator:: |
|
2597 // ----------------------------------------------------------------------------- |
|
2598 // |
|
2599 |
|
2600 |
|
2601 TDesC8& CAttributeDesignator::GetAttributeid() |
|
2602 { |
|
2603 return *iAttributeId; |
|
2604 } |
|
2605 |
|
2606 // ----------------------------------------------------------------------------- |
|
2607 // CAttributeDesignator:: |
|
2608 // ----------------------------------------------------------------------------- |
|
2609 // |
|
2610 |
|
2611 |
|
2612 TDesC8& CAttributeDesignator::GetDataType() |
|
2613 { |
|
2614 return *iDataType; |
|
2615 } |
|
2616 |
|
2617 // ----------------------------------------------------------------------------- |
|
2618 // CAttributeDesignator:: |
|
2619 // ----------------------------------------------------------------------------- |
|
2620 // |
|
2621 |
|
2622 |
|
2623 TBool CAttributeDesignator::ValidElement() |
|
2624 { |
|
2625 return iAttributeId && iDataType; |
|
2626 } |
|
2627 |
|
2628 // ----------------------------------------------------------------------------- |
|
2629 // CAttributeDesignator:: |
|
2630 // ----------------------------------------------------------------------------- |
|
2631 // |
|
2632 |
|
2633 |
|
2634 |
|
2635 void CAttributeDesignator::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
2636 { |
|
2637 if ( aName == PolicyLanguage::NativeLanguage::AttributeDesignators::AttributeId ) |
|
2638 { |
|
2639 iAttributeId = aValue.AllocL(); |
|
2640 } |
|
2641 else |
|
2642 if ( aName == PolicyLanguage::NativeLanguage::AttributeDesignators::DataType) |
|
2643 { |
|
2644 if ( aParser) |
|
2645 { |
|
2646 aParser->CheckDataTypeL( aValue); |
|
2647 } |
|
2648 iDataType = aValue.AllocL(); |
|
2649 } |
|
2650 else |
|
2651 { |
|
2652 if ( aParser) |
|
2653 { |
|
2654 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName); |
|
2655 } |
|
2656 } |
|
2657 } |
|
2658 |
|
2659 // ----------------------------------------------------------------------------- |
|
2660 // CAttributeDesignator:: |
|
2661 // ----------------------------------------------------------------------------- |
|
2662 // |
|
2663 |
|
2664 |
|
2665 HBufC8 * CAttributeDesignator::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &/*aMode*/ ) |
|
2666 { |
|
2667 RDEBUG("PolicyEngineServer: Decode Attribute Designator element"); |
|
2668 |
|
2669 |
|
2670 __ASSERT_ALWAYS ( iAttributeId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
2671 __ASSERT_ALWAYS ( iDataType, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
2672 |
|
2673 CheckAllElementsL(); |
|
2674 TElementReserver reserver( Container()); |
|
2675 |
|
2676 _LIT8( DecodeFormat, "<%S %S=\"%S\" %S=\"%S\"/>"); |
|
2677 |
|
2678 TInt size(25); |
|
2679 size += PolicyLanguage::AttributeDesignators::AttributeId[ aLanguage].Length(); |
|
2680 const TDesC8& attributeId = SelectCorrectValue( aLanguage, *iAttributeId); |
|
2681 size += attributeId.Length(); |
|
2682 |
|
2683 size += PolicyLanguage::AttributeDesignators::DataType[ aLanguage].Length(); |
|
2684 const TDesC8& dataType = SelectCorrectValue( aLanguage, *iDataType); |
|
2685 size += dataType.Length(); |
|
2686 |
|
2687 TPtrC8 ptr; |
|
2688 if ( iElementType == ESubjectAttributeDesignator ) |
|
2689 ptr.Set( PolicyLanguage::AttributeDesignators::SubjectAttributeDesignator[ aLanguage]); |
|
2690 else if ( iElementType == EActionAttributeDesignator ) |
|
2691 ptr.Set( PolicyLanguage::AttributeDesignators::ActionAttributeDesignator[ aLanguage]); |
|
2692 else if ( iElementType == EResourceAttributeDesignator ) |
|
2693 ptr.Set( PolicyLanguage::AttributeDesignators::ResourceAttributeDesignator[ aLanguage]); |
|
2694 else |
|
2695 ptr.Set( PolicyLanguage::AttributeDesignators::EnvironmentAttributeDesignator[ aLanguage]); |
|
2696 |
|
2697 size += 1 * ptr.Length(); |
|
2698 |
|
2699 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
2700 |
|
2701 hbuf->Des().Format( DecodeFormat, &ptr, |
|
2702 &PolicyLanguage::AttributeDesignators::AttributeId[ aLanguage], |
|
2703 &attributeId, |
|
2704 &PolicyLanguage::AttributeDesignators::DataType[ aLanguage], |
|
2705 &dataType); |
|
2706 |
|
2707 CleanupStack::Pop( hbuf); |
|
2708 |
|
2709 reserver.Release(); |
|
2710 |
|
2711 return hbuf; |
|
2712 } |
|
2713 |
|
2714 // ----------------------------------------------------------------------------- |
|
2715 // CAttributeDesignator:: |
|
2716 // ----------------------------------------------------------------------------- |
|
2717 // |
|
2718 |
|
2719 |
|
2720 CAttribute * CAttributeDesignator::GetAttributeFromRequestContext( CPolicyProcessor * aRequestContext) |
|
2721 { |
|
2722 __ASSERT_ALWAYS ( iAttributeId, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
2723 |
|
2724 CPolicyProcessor::RAttributeList * container = NULL; |
|
2725 |
|
2726 switch ( iElementType) |
|
2727 { |
|
2728 case ESubjectAttributeDesignator : |
|
2729 container = aRequestContext->Subjects(); |
|
2730 break; |
|
2731 case EActionAttributeDesignator : |
|
2732 container = aRequestContext->Actions(); |
|
2733 break; |
|
2734 case EResourceAttributeDesignator : |
|
2735 container = aRequestContext->Resources(); |
|
2736 break; |
|
2737 case EEnvironmentAttributeDesignator : |
|
2738 container = aRequestContext->Environments(); |
|
2739 break; |
|
2740 default: |
|
2741 break; |
|
2742 } |
|
2743 |
|
2744 |
|
2745 __ASSERT_ALWAYS ( container, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
2746 |
|
2747 for ( TInt i(0); i < container->Count(); i++) |
|
2748 { |
|
2749 CAttribute * matchAttribute = (*container)[i]; |
|
2750 __ASSERT_ALWAYS ( matchAttribute, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
2751 |
|
2752 RDEBUG8_2("PolicyEngineServer: Attribute in request context: %S", &matchAttribute->AttributeId()); |
|
2753 if ( matchAttribute->AttributeId() == *iAttributeId ) |
|
2754 { |
|
2755 return matchAttribute; |
|
2756 } |
|
2757 } |
|
2758 |
|
2759 return NULL; |
|
2760 } |
|
2761 |
|
2762 // ----------------------------------------------------------------------------- |
|
2763 // CSubjectAttributeDesignator:: |
|
2764 // ----------------------------------------------------------------------------- |
|
2765 // |
|
2766 |
|
2767 |
|
2768 |
|
2769 CSubjectAttributeDesignator::CSubjectAttributeDesignator() |
|
2770 : CAttributeDesignator() |
|
2771 { |
|
2772 iElementType = ESubjectAttributeDesignator; |
|
2773 iElementName.Set( PolicyLanguage::NativeLanguage::AttributeDesignators::SubjectAttributeDesignator); |
|
2774 |
|
2775 } |
|
2776 |
|
2777 // ----------------------------------------------------------------------------- |
|
2778 // CSubjectAttributeDesignator:: |
|
2779 // ----------------------------------------------------------------------------- |
|
2780 // |
|
2781 |
|
2782 CSubjectAttributeDesignator::~CSubjectAttributeDesignator() |
|
2783 { |
|
2784 |
|
2785 } |
|
2786 |
|
2787 // ----------------------------------------------------------------------------- |
|
2788 // CSubjectAttributeDesignator:: |
|
2789 // ----------------------------------------------------------------------------- |
|
2790 // |
|
2791 |
|
2792 CSubjectAttributeDesignator * CSubjectAttributeDesignator::NewL() |
|
2793 { |
|
2794 CSubjectAttributeDesignator * self = new (ELeave) CSubjectAttributeDesignator(); |
|
2795 return self; |
|
2796 } |
|
2797 |
|
2798 // ----------------------------------------------------------------------------- |
|
2799 // CSubjectAttributeDesignator:: |
|
2800 // ----------------------------------------------------------------------------- |
|
2801 // |
|
2802 |
|
2803 |
|
2804 TBool CSubjectAttributeDesignator::IdentificateType( const TDesC8& aElementName) |
|
2805 { |
|
2806 return ( aElementName == PolicyLanguage::NativeLanguage::AttributeDesignators::SubjectAttributeDesignator); |
|
2807 } |
|
2808 |
|
2809 // ----------------------------------------------------------------------------- |
|
2810 // CActionAttributeDesignator:: |
|
2811 // ----------------------------------------------------------------------------- |
|
2812 // |
|
2813 |
|
2814 |
|
2815 CActionAttributeDesignator::CActionAttributeDesignator() |
|
2816 : CAttributeDesignator() |
|
2817 { |
|
2818 iElementType = EActionAttributeDesignator; |
|
2819 iElementName.Set( PolicyLanguage::NativeLanguage::AttributeDesignators::ActionAttributeDesignator); |
|
2820 |
|
2821 } |
|
2822 |
|
2823 // ----------------------------------------------------------------------------- |
|
2824 // CActionAttributeDesignator:: |
|
2825 // ----------------------------------------------------------------------------- |
|
2826 // |
|
2827 |
|
2828 |
|
2829 CActionAttributeDesignator::~CActionAttributeDesignator() |
|
2830 { |
|
2831 |
|
2832 } |
|
2833 |
|
2834 // ----------------------------------------------------------------------------- |
|
2835 // CActionAttributeDesignator:: |
|
2836 // ----------------------------------------------------------------------------- |
|
2837 // |
|
2838 |
|
2839 |
|
2840 CElementBase * CActionAttributeDesignator::NewL() |
|
2841 { |
|
2842 CActionAttributeDesignator * self = new (ELeave) CActionAttributeDesignator(); |
|
2843 return self; |
|
2844 } |
|
2845 |
|
2846 // ----------------------------------------------------------------------------- |
|
2847 // CActionAttributeDesignator:: |
|
2848 // ----------------------------------------------------------------------------- |
|
2849 // |
|
2850 |
|
2851 |
|
2852 TBool CActionAttributeDesignator::IdentificateType( const TDesC8& aElementName) |
|
2853 { |
|
2854 return ( aElementName == PolicyLanguage::NativeLanguage::AttributeDesignators::ActionAttributeDesignator); |
|
2855 } |
|
2856 |
|
2857 // ----------------------------------------------------------------------------- |
|
2858 // CResourceAttributeDesignator:: |
|
2859 // ----------------------------------------------------------------------------- |
|
2860 // |
|
2861 |
|
2862 |
|
2863 CResourceAttributeDesignator::CResourceAttributeDesignator() |
|
2864 : CAttributeDesignator() |
|
2865 { |
|
2866 iElementType = EResourceAttributeDesignator; |
|
2867 iElementName.Set( PolicyLanguage::NativeLanguage::AttributeDesignators::ResourceAttributeDesignator); |
|
2868 |
|
2869 } |
|
2870 |
|
2871 // ----------------------------------------------------------------------------- |
|
2872 // CResourceAttributeDesignator:: |
|
2873 // ----------------------------------------------------------------------------- |
|
2874 // |
|
2875 |
|
2876 CResourceAttributeDesignator::~CResourceAttributeDesignator() |
|
2877 { |
|
2878 |
|
2879 } |
|
2880 |
|
2881 // ----------------------------------------------------------------------------- |
|
2882 // CResourceAttributeDesignator::NewL |
|
2883 // ----------------------------------------------------------------------------- |
|
2884 // |
|
2885 |
|
2886 CElementBase * CResourceAttributeDesignator::NewL() |
|
2887 { |
|
2888 CResourceAttributeDesignator * self = new (ELeave) CResourceAttributeDesignator(); |
|
2889 return self; |
|
2890 } |
|
2891 |
|
2892 // ----------------------------------------------------------------------------- |
|
2893 // CResourceAttributeDesignator::IdentificateType |
|
2894 // ----------------------------------------------------------------------------- |
|
2895 // |
|
2896 |
|
2897 TBool CResourceAttributeDesignator::IdentificateType( const TDesC8& aElementName) |
|
2898 { |
|
2899 return ( aElementName == PolicyLanguage::NativeLanguage::AttributeDesignators::ResourceAttributeDesignator); |
|
2900 } |
|
2901 |
|
2902 // ----------------------------------------------------------------------------- |
|
2903 // CEnvironmentAttributeDesignator::CEnvironmentAttributeDesignator |
|
2904 // ----------------------------------------------------------------------------- |
|
2905 // |
|
2906 |
|
2907 CEnvironmentAttributeDesignator::CEnvironmentAttributeDesignator() |
|
2908 : CAttributeDesignator() |
|
2909 { |
|
2910 iElementType = EEnvironmentAttributeDesignator; |
|
2911 iElementName.Set( PolicyLanguage::NativeLanguage::AttributeDesignators::EnvironmentAttributeDesignator); |
|
2912 |
|
2913 } |
|
2914 |
|
2915 // ----------------------------------------------------------------------------- |
|
2916 // CEnvironmentAttributeDesignator::~CEnvironmentAttributeDesignator |
|
2917 // ----------------------------------------------------------------------------- |
|
2918 // |
|
2919 |
|
2920 |
|
2921 CEnvironmentAttributeDesignator::~CEnvironmentAttributeDesignator() |
|
2922 { |
|
2923 |
|
2924 } |
|
2925 |
|
2926 // ----------------------------------------------------------------------------- |
|
2927 // CEnvironmentAttributeDesignator::NewL |
|
2928 // ----------------------------------------------------------------------------- |
|
2929 // |
|
2930 |
|
2931 |
|
2932 CElementBase * CEnvironmentAttributeDesignator::NewL() |
|
2933 { |
|
2934 CEnvironmentAttributeDesignator * self = new (ELeave) CEnvironmentAttributeDesignator(); |
|
2935 return self; |
|
2936 } |
|
2937 |
|
2938 // ----------------------------------------------------------------------------- |
|
2939 // CEnvironmentAttributeDesignator::IdentificateType |
|
2940 // ----------------------------------------------------------------------------- |
|
2941 // |
|
2942 |
|
2943 |
|
2944 TBool CEnvironmentAttributeDesignator::IdentificateType( const TDesC8& aElementName) |
|
2945 { |
|
2946 return ( aElementName == PolicyLanguage::NativeLanguage::AttributeDesignators::EnvironmentAttributeDesignator); |
|
2947 } |
|
2948 |
|
2949 // ----------------------------------------------------------------------------- |
|
2950 // CMatchObject::CMatchObject |
|
2951 // ----------------------------------------------------------------------------- |
|
2952 // |
|
2953 |
|
2954 CMatchObject::CMatchObject( const TDesC8& aElementName) |
|
2955 { |
|
2956 if ( aElementName == PolicyLanguage::NativeLanguage::MatchObject::SubjectMatch ) |
|
2957 { |
|
2958 iElementType = ESubjectMatch; |
|
2959 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::SubjectMatch); |
|
2960 } |
|
2961 else |
|
2962 if ( aElementName == PolicyLanguage::NativeLanguage::MatchObject::ResourceMatch) |
|
2963 { |
|
2964 iElementType = EResourceMatch; |
|
2965 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::ResourceMatch); |
|
2966 } |
|
2967 else |
|
2968 if ( aElementName == PolicyLanguage::NativeLanguage::MatchObject::ActionMatch ) |
|
2969 { |
|
2970 iElementType = EActionMatch; |
|
2971 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::ActionMatch); |
|
2972 } |
|
2973 else |
|
2974 { |
|
2975 iElementType = EEnvironmentMatch; |
|
2976 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::EnvironmentMatch); |
|
2977 } |
|
2978 |
|
2979 iSaveType = ESubElement; |
|
2980 } |
|
2981 |
|
2982 |
|
2983 |
|
2984 // ----------------------------------------------------------------------------- |
|
2985 // CMatchObject::CMatchObject |
|
2986 // ----------------------------------------------------------------------------- |
|
2987 // |
|
2988 |
|
2989 CMatchObject::CMatchObject( TNativeElementTypes aElementType) |
|
2990 { |
|
2991 iElementType = aElementType; |
|
2992 |
|
2993 switch ( aElementType) |
|
2994 { |
|
2995 case ESubjectMatch: |
|
2996 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::SubjectMatch); |
|
2997 break; |
|
2998 case EResourceMatch: |
|
2999 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::ResourceMatch); |
|
3000 break; |
|
3001 case EActionMatch: |
|
3002 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::ActionMatch); |
|
3003 break; |
|
3004 case EEnvironmentMatch: |
|
3005 iElementName.Set( PolicyLanguage::NativeLanguage::MatchObject::EnvironmentMatch); |
|
3006 break; |
|
3007 } |
|
3008 } |
|
3009 |
|
3010 // ----------------------------------------------------------------------------- |
|
3011 // CMatchObject::NewL |
|
3012 // ----------------------------------------------------------------------------- |
|
3013 // |
|
3014 |
|
3015 CElementBase * CMatchObject::NewL( TNativeElementTypes aElementType) |
|
3016 { |
|
3017 CMatchObject * self = new (ELeave) CMatchObject(aElementType); |
|
3018 return self; |
|
3019 } |
|
3020 |
|
3021 // ----------------------------------------------------------------------------- |
|
3022 // CMatchObject::~CMatchObject |
|
3023 // ----------------------------------------------------------------------------- |
|
3024 // |
|
3025 |
|
3026 CMatchObject::~CMatchObject() |
|
3027 { |
|
3028 delete iMatchId; |
|
3029 } |
|
3030 |
|
3031 // ----------------------------------------------------------------------------- |
|
3032 // CMatchObject::NewL |
|
3033 // ----------------------------------------------------------------------------- |
|
3034 // |
|
3035 |
|
3036 CElementBase * CMatchObject::NewL( const TDesC8& aElementName) |
|
3037 { |
|
3038 CMatchObject * self = new (ELeave) CMatchObject(aElementName); |
|
3039 return self; |
|
3040 } |
|
3041 |
|
3042 // ----------------------------------------------------------------------------- |
|
3043 // CMatchObject::ValidElement |
|
3044 // ----------------------------------------------------------------------------- |
|
3045 // |
|
3046 |
|
3047 TBool CMatchObject::ValidElement() |
|
3048 { |
|
3049 return iMatchId && iDesignator && iMatchValue; |
|
3050 } |
|
3051 |
|
3052 // ----------------------------------------------------------------------------- |
|
3053 // CMatchObject::AttributeDesignator |
|
3054 // ----------------------------------------------------------------------------- |
|
3055 // |
|
3056 |
|
3057 CAttributeDesignator* CMatchObject::AttributeDesignator() |
|
3058 { |
|
3059 return iDesignator; |
|
3060 } |
|
3061 |
|
3062 // ----------------------------------------------------------------------------- |
|
3063 // CMatchObject::AttributeValue |
|
3064 // ----------------------------------------------------------------------------- |
|
3065 // |
|
3066 |
|
3067 CAttributeValue* CMatchObject::AttributeValue() |
|
3068 { |
|
3069 return iMatchValue; |
|
3070 } |
|
3071 |
|
3072 // ----------------------------------------------------------------------------- |
|
3073 // CMatchObject::MatchId |
|
3074 // ----------------------------------------------------------------------------- |
|
3075 // |
|
3076 HBufC8* CMatchObject::MatchId() |
|
3077 { |
|
3078 return iMatchId; |
|
3079 } |
|
3080 |
|
3081 |
|
3082 // ----------------------------------------------------------------------------- |
|
3083 // CMatchObject::IdentificateType |
|
3084 // ----------------------------------------------------------------------------- |
|
3085 // |
|
3086 |
|
3087 TBool CMatchObject::IdentificateType( const TDesC8& aElementName) |
|
3088 { |
|
3089 return ( aElementName == PolicyLanguage::NativeLanguage::MatchObject::SubjectMatch || |
|
3090 aElementName == PolicyLanguage::NativeLanguage::MatchObject::ActionMatch || |
|
3091 aElementName == PolicyLanguage::NativeLanguage::MatchObject::EnvironmentMatch || |
|
3092 aElementName == PolicyLanguage::NativeLanguage::MatchObject::ResourceMatch ); |
|
3093 } |
|
3094 |
|
3095 // ----------------------------------------------------------------------------- |
|
3096 // CMatchObject::CheckContainer |
|
3097 // ----------------------------------------------------------------------------- |
|
3098 // |
|
3099 |
|
3100 TBool CMatchObject::CheckMatchObject( const TDesC8& aType, const TDesC8& aAttribute, const TDesC8& aValue) |
|
3101 { |
|
3102 using namespace PolicyLanguage::Constants; |
|
3103 |
|
3104 TBool response = EFalse; |
|
3105 |
|
3106 if ( (aType == Subject && iElementType == ESubjectMatch) || |
|
3107 (aType == Action && iElementType == EActionMatch) || |
|
3108 (aType == Resource && iElementType == EResourceMatch) || |
|
3109 (aType == Environment && iElementType == EEnvironmentMatch) ) |
|
3110 { |
|
3111 |
|
3112 |
|
3113 __ASSERT_ALWAYS ( iMatchValue, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
3114 __ASSERT_ALWAYS ( iDesignator, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
3115 |
|
3116 response = ETrue; |
|
3117 |
|
3118 if ( aValue != Any) |
|
3119 { |
|
3120 if ( iMatchValue->Data()->Value() != aValue ) |
|
3121 { |
|
3122 response = EFalse; |
|
3123 } |
|
3124 } |
|
3125 |
|
3126 if ( response && iDesignator->GetAttributeid() != aAttribute) |
|
3127 { |
|
3128 response = EFalse; |
|
3129 } |
|
3130 } |
|
3131 |
|
3132 return response; |
|
3133 } |
|
3134 |
|
3135 // ----------------------------------------------------------------------------- |
|
3136 // CMatchObject::AddAttributeL |
|
3137 // ----------------------------------------------------------------------------- |
|
3138 // |
|
3139 |
|
3140 |
|
3141 |
|
3142 |
|
3143 void CMatchObject::AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) |
|
3144 { |
|
3145 if ( aName == PolicyLanguage::NativeLanguage::MatchObject::MatchId ) |
|
3146 { |
|
3147 if ( aParser) |
|
3148 { |
|
3149 aParser->CheckFunctionIdL( iElementType, aValue); |
|
3150 } |
|
3151 iMatchId = aValue.AllocL(); |
|
3152 } |
|
3153 else |
|
3154 { |
|
3155 if ( aParser) |
|
3156 { |
|
3157 aParser->HandleErrorL( ParserErrors::UnexpectedAttribute, aName ); |
|
3158 } |
|
3159 } |
|
3160 } |
|
3161 |
|
3162 // ----------------------------------------------------------------------------- |
|
3163 // CMatchObject::AddElementL |
|
3164 // ----------------------------------------------------------------------------- |
|
3165 // |
|
3166 |
|
3167 void CMatchObject::AddElementL( CPolicyParser *aParser, CElementBase * aElement) |
|
3168 { |
|
3169 if ( aElement->ElementType() == ESubjectAttributeDesignator || |
|
3170 aElement->ElementType() == EActionAttributeDesignator || |
|
3171 aElement->ElementType() == EResourceAttributeDesignator || |
|
3172 aElement->ElementType() == EEnvironmentAttributeDesignator) |
|
3173 { |
|
3174 if ( aParser ) |
|
3175 { |
|
3176 aParser->HandleErrorL( iDesignator, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
3177 } |
|
3178 iDesignator = (CAttributeDesignator*) aElement; |
|
3179 AddToElementListL( aElement, ETrue); |
|
3180 } |
|
3181 else if ( aElement->ElementType() == EAttributeValue) |
|
3182 { |
|
3183 if ( aParser ) |
|
3184 { |
|
3185 aParser->HandleErrorL( iMatchValue, ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
3186 } |
|
3187 iMatchValue = (CAttributeValue*) aElement; |
|
3188 AddToElementListL( aElement, ETrue); |
|
3189 } |
|
3190 else |
|
3191 { |
|
3192 aParser->HandleErrorL( ParserErrors::UnexpectedElement, aParser->ActiveElementName()); |
|
3193 } |
|
3194 }; |
|
3195 |
|
3196 // ----------------------------------------------------------------------------- |
|
3197 // CMatchObject:: |
|
3198 // ----------------------------------------------------------------------------- |
|
3199 // |
|
3200 |
|
3201 HBufC8 * CMatchObject::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode ) |
|
3202 { |
|
3203 RDEBUG("Decode MatchObject element"); |
|
3204 |
|
3205 __ASSERT_ALWAYS ( iDesignator, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
3206 __ASSERT_ALWAYS ( iMatchValue, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
3207 __ASSERT_ALWAYS ( iMatchId, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
3208 |
|
3209 CheckAllElementsL(); |
|
3210 TElementReserver reserver( Container()); |
|
3211 |
|
3212 |
|
3213 _LIT8( DecodeFormat, "<%S %S=\"%S\"> %S %S </%S>"); |
|
3214 |
|
3215 TInt size(25); |
|
3216 size += PolicyLanguage::MatchObject::MatchId[ aLanguage].Length(); |
|
3217 const TDesC8& matchId = SelectCorrectValue( aLanguage, *iMatchId); |
|
3218 size += matchId.Length(); |
|
3219 |
|
3220 TPtrC8 ptr; |
|
3221 if ( iElementType == ESubjectMatch ) |
|
3222 ptr.Set( PolicyLanguage::MatchObject::SubjectMatch[ aLanguage]); |
|
3223 else if ( iElementType == EActionMatch ) |
|
3224 ptr.Set( PolicyLanguage::MatchObject::ActionMatch[ aLanguage]); |
|
3225 else if ( iElementType == EResourceMatch ) |
|
3226 ptr.Set( PolicyLanguage::MatchObject::ResourceMatch[ aLanguage]); |
|
3227 else |
|
3228 ptr.Set( PolicyLanguage::MatchObject::EnvironmentMatch[ aLanguage]); |
|
3229 |
|
3230 size += 2 * ptr.Length(); |
|
3231 |
|
3232 HBufC8 * matchValue = DecodeElementOrIdL( aLanguage, iMatchValue, aMode);//EFullMode); |
|
3233 |
|
3234 CleanupStack::PushL( matchValue); |
|
3235 |
|
3236 size += matchValue->Length(); |
|
3237 |
|
3238 |
|
3239 HBufC8 * designator = DecodeElementOrIdL( aLanguage, iDesignator, aMode); //EFullMode); |
|
3240 |
|
3241 CleanupStack::PushL( designator); |
|
3242 |
|
3243 size += designator->Length(); |
|
3244 |
|
3245 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
3246 |
|
3247 hbuf->Des().Format( DecodeFormat, &ptr, |
|
3248 &PolicyLanguage::MatchObject::MatchId[ aLanguage], |
|
3249 &matchId, |
|
3250 matchValue, |
|
3251 designator, |
|
3252 &ptr); |
|
3253 |
|
3254 CleanupStack::Pop( hbuf); |
|
3255 CleanupStack::PopAndDestroy( 2, matchValue); |
|
3256 |
|
3257 |
|
3258 reserver.Release(); |
|
3259 |
|
3260 return hbuf; |
|
3261 } |
|
3262 |
|
3263 // ----------------------------------------------------------------------------- |
|
3264 // CMatchObject::MatchL |
|
3265 // ----------------------------------------------------------------------------- |
|
3266 // |
|
3267 |
|
3268 |
|
3269 TMatchResponse CMatchObject::MatchL( CPolicyProcessor* aPolicyProcessor) |
|
3270 { |
|
3271 #ifndef __POLICY_BASE_CREATOR_TOOL |
|
3272 |
|
3273 RDEBUG("PolicyEngineServer: CMatchObject::MatchL"); |
|
3274 |
|
3275 __ASSERT_ALWAYS ( iDesignator, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
3276 __ASSERT_ALWAYS ( iMatchValue, User::Panic(PolicyExecutionPanic, KErrCorrupt)); |
|
3277 |
|
3278 |
|
3279 TElementReserver designatorReserver( iDesignator); |
|
3280 TElementReserver matchReserver( iMatchValue); |
|
3281 |
|
3282 #ifdef _DEBUG |
|
3283 switch ( iElementType) |
|
3284 { |
|
3285 case ESubjectMatch: |
|
3286 RDEBUG8_2("PolicyEngineServer: SubjectMatch - AttrId: %S", &iDesignator->GetAttributeid()); |
|
3287 break; |
|
3288 case EActionMatch: |
|
3289 RDEBUG8_2("PolicyEngineServer: ActionMatch - AttrId: %S", &iDesignator->GetAttributeid()); |
|
3290 break; |
|
3291 case EResourceMatch: |
|
3292 RDEBUG8_2("PolicyEngineServer: ResourceMatch - AttrId: %S", &iDesignator->GetAttributeid()); |
|
3293 break; |
|
3294 default: |
|
3295 RDEBUG8_2("PolicyEngineServer: EnvinromentMatch - AttrId: %S", &iDesignator->GetAttributeid()); |
|
3296 break; |
|
3297 } |
|
3298 #endif |
|
3299 |
|
3300 CAttribute * requestAttribute = iDesignator->GetAttributeFromRequestContext( aPolicyProcessor); |
|
3301 |
|
3302 TMatchResponse response = EUnMatch; |
|
3303 |
|
3304 if ( requestAttribute) |
|
3305 { |
|
3306 if ( iDesignator->GetDataType() != requestAttribute->AttributeType() ) |
|
3307 { |
|
3308 RDEBUG("PolicyEngineServer: Datatypes doesn't match between request and policy attributes -> INDETERMINATE!"); |
|
3309 response = EIndeterminate; |
|
3310 } |
|
3311 else |
|
3312 { |
|
3313 if ( aPolicyProcessor->MatchFunctionL( *iMatchId, iMatchValue->Data(), requestAttribute->AttributeValue()->Data())) |
|
3314 { |
|
3315 RDEBUG8_3("PolicyEngineServer: MATCH: %S == %S", &iMatchValue->Data()->Value(), &requestAttribute->AttributeValue()->Data()->Value()); |
|
3316 response = EMatch; |
|
3317 } |
|
3318 else |
|
3319 { |
|
3320 RDEBUG8_3("PolicyEngineServer: UNMATCH: %S != %S", &iMatchValue->Data()->Value(), &requestAttribute->AttributeValue()->Data()->Value()); |
|
3321 } |
|
3322 } |
|
3323 } |
|
3324 else |
|
3325 { |
|
3326 |
|
3327 } |
|
3328 |
|
3329 matchReserver.Release(); |
|
3330 designatorReserver.Release(); |
|
3331 return response; |
|
3332 |
|
3333 #endif// __POLICY_BASE_CREATOR_TOOL |
|
3334 } |
|
3335 |
|
3336 |
|
3337 // ----------------------------------------------------------------------------- |
|
3338 // CMatchObject::AddIdElementL |
|
3339 // ----------------------------------------------------------------------------- |
|
3340 // |
|
3341 |
|
3342 void CMatchObject::AddIdElementL( CElementBase * aElement) |
|
3343 { |
|
3344 __ASSERT_ALWAYS ( aElement, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
3345 |
|
3346 switch ( aElement->ElementType()) |
|
3347 { |
|
3348 case ESubjectAttributeDesignator: |
|
3349 case EActionAttributeDesignator: |
|
3350 case EResourceAttributeDesignator: |
|
3351 case EEnvironmentAttributeDesignator: |
|
3352 iDesignator = (CAttributeDesignator*) aElement; |
|
3353 break; |
|
3354 |
|
3355 case EAttributeValue : |
|
3356 iMatchValue = (CAttributeValue*) aElement; |
|
3357 break; |
|
3358 } |
|
3359 |
|
3360 AddToElementListL( aElement, EFalse); |
|
3361 } |
|
3362 |
|
3363 // ----------------------------------------------------------------------------- |
|
3364 // CDescription:: |
|
3365 // ----------------------------------------------------------------------------- |
|
3366 // |
|
3367 |
|
3368 CDescription::CDescription() |
|
3369 { |
|
3370 iElementType = EDescription; |
|
3371 iElementName.Set( PolicyLanguage::NativeLanguage::Description::Description); |
|
3372 } |
|
3373 |
|
3374 // ----------------------------------------------------------------------------- |
|
3375 // CDescription:: |
|
3376 // ----------------------------------------------------------------------------- |
|
3377 // |
|
3378 |
|
3379 CDescription::~CDescription() |
|
3380 { |
|
3381 delete iDescription; |
|
3382 } |
|
3383 |
|
3384 // ----------------------------------------------------------------------------- |
|
3385 // CDescription:: |
|
3386 // ----------------------------------------------------------------------------- |
|
3387 // |
|
3388 |
|
3389 CElementBase * CDescription::NewL() |
|
3390 { |
|
3391 return new (ELeave) CDescription(); |
|
3392 } |
|
3393 |
|
3394 // ----------------------------------------------------------------------------- |
|
3395 // CDescription:: |
|
3396 // ----------------------------------------------------------------------------- |
|
3397 // |
|
3398 |
|
3399 TBool CDescription::IdentificateType( const TDesC8& aElementName) |
|
3400 { |
|
3401 return aElementName == PolicyLanguage::NativeLanguage::Description::Description; |
|
3402 } |
|
3403 |
|
3404 // ----------------------------------------------------------------------------- |
|
3405 // CDescription:: |
|
3406 // ----------------------------------------------------------------------------- |
|
3407 // |
|
3408 |
|
3409 HBufC8 * CDescription::DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &/*aMode*/ ) |
|
3410 { |
|
3411 RDEBUG("PolicyEngineServer: Decode Description element"); |
|
3412 |
|
3413 |
|
3414 __ASSERT_ALWAYS ( iDescription, User::Panic(PolicyParserPanic, KErrCorrupt)); |
|
3415 |
|
3416 _LIT8( DecodeFormat, "<%S>%S</%S>"); |
|
3417 |
|
3418 TInt size(5); |
|
3419 TPtrC8 ptr = PolicyLanguage::Description::Description[ aLanguage]; |
|
3420 size += ptr.Length() * 2; |
|
3421 |
|
3422 size += iDescription->Length(); |
|
3423 |
|
3424 HBufC8 * hbuf = HBufC8::NewLC( size); |
|
3425 hbuf->Des().Format( DecodeFormat, &ptr, iDescription, &ptr); |
|
3426 CleanupStack::Pop( hbuf); |
|
3427 |
|
3428 return hbuf; |
|
3429 } |
|
3430 |
|
3431 // ----------------------------------------------------------------------------- |
|
3432 // CDescription:: |
|
3433 // ----------------------------------------------------------------------------- |
|
3434 // |
|
3435 |
|
3436 void CDescription::AddContentL( CPolicyParser */*aParser*/, const TDesC8& aName) |
|
3437 { |
|
3438 if ( iDescription ) |
|
3439 { |
|
3440 iDescription = iDescription->ReAllocL( iDescription->Length() + aName.Length()); |
|
3441 iDescription->Des().Append( aName); |
|
3442 } |
|
3443 else |
|
3444 { |
|
3445 iDescription = aName.AllocL(); |
|
3446 } |
|
3447 }; |
|
3448 |
|
3449 // ----------------------------------------------------------------------------- |
|
3450 // CDescription:: |
|
3451 // ----------------------------------------------------------------------------- |
|
3452 // |
|
3453 |
|
3454 HBufC8 * CDescription::DescriptionText() |
|
3455 { |
|
3456 return iDescription; |
|
3457 } |
|
3458 |
|
3459 // ----------------------------------------------------------------------------- |
|
3460 // CDescription:: |
|
3461 // ----------------------------------------------------------------------------- |
|
3462 // |
|
3463 |
|
3464 TBool CDescription::ValidElement() |
|
3465 { |
|
3466 return ETrue; |
|
3467 } |
|
3468 |