policymanagement/policyengine/policyengineserver/src/PolicyParser.cpp
changeset 0 b497e44ab2fc
child 22 19fb38abab1d
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     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 "PolicyParser.h"
       
    22 #include "ElementBase.h"
       
    23 #include "elements.h"
       
    24 #include "DataTypes.h"
       
    25 #include "debug.h"
       
    26 #include "PolicyStorage.h"
       
    27 #include "XACMLconstants.h"
       
    28 #include "ErrorCodes.h"
       
    29 
       
    30 #include <f32file.h>
       
    31 #include <e32base.h>
       
    32 #include <s32file.h>
       
    33 
       
    34 // MACROS
       
    35 // CONSTANTS
       
    36 
       
    37 _LIT8( KCDataStart, "<![CDATA[");
       
    38 const TInt KCDataStartLength = 9;
       
    39 const TInt KCDataEndLength = 3;
       
    40 _LIT8( KCDataEnd, "]]>");
       
    41 
       
    42 // DATA TYPES
       
    43 // FUNCTION PROTOTYPES
       
    44 
       
    45 
       
    46 namespace ParserUtility
       
    47 {
       
    48 	// -----------------------------------------------------------------------------
       
    49 	// ParserUtility::ContainsCDataField
       
    50 	// -----------------------------------------------------------------------------
       
    51 	//
       
    52 	TBool ContainsCDataField( TPtrC8& aChunk)
       
    53 	{
       
    54 		//Find CData indicator
       
    55 		return 0 <= aChunk.Find( KCDataStart);
       
    56 	}
       
    57 	
       
    58 	// -----------------------------------------------------------------------------
       
    59 	// ParserUtility::ReadCDataArea
       
    60 	// -----------------------------------------------------------------------------
       
    61 	//
       
    62 	void ReadCDataAreaL( TPtrC8& aCDataArea, TPtrC8& aChunk, TPtrC8& aFinalPart)
       
    63 	{
       
    64 		//find cdata start index and calculate nested cdata fields
       
    65 		TPtrC8 temp = aFinalPart;
       
    66 		TInt tempIndex;
       
    67 		TInt cdatastart = KErrNotFound;
       
    68 
       
    69 		TInt cdataCount = 0;
       
    70 		while (	KErrNotFound != (tempIndex = temp.Find( KCDataStart)))
       
    71 		{
       
    72 			if ( cdatastart == KErrNotFound)
       
    73 			{
       
    74 				//save cdata field start
       
    75 				cdatastart = tempIndex;
       
    76 			}
       
    77 			temp.Set( temp.Mid(tempIndex + KCDataStartLength));
       
    78 			cdataCount++;	
       
    79 		}
       
    80 		
       
    81 		User::LeaveIfError( cdatastart);
       
    82 		
       
    83 		//find end location for cdata field (dismiss nested CDATA end marks)
       
    84 		TInt cdataend = 0;
       
    85 		temp.Set( aFinalPart);
       
    86 			
       
    87 		while ( cdataCount-- )
       
    88 		{
       
    89 			TInt current = temp.Find( KCDataEnd);
       
    90 			temp.Set( temp.Mid(current + KCDataEndLength ));
       
    91 			cdataend += current + KCDataEndLength;
       
    92 		}
       
    93 		
       
    94 		if ( cdataCount != -1 )
       
    95 		{
       
    96 			User::Leave( KErrCorrupt);
       
    97 		}
       
    98 
       
    99 		//set cdata area
       
   100 		aCDataArea.Set( aFinalPart.Mid( cdatastart));
       
   101 		aCDataArea.Set( aCDataArea.Left( cdataend - cdatastart));
       
   102 
       
   103 		
       
   104 		//shrink cdata part from chunk and set aFinalPart to begin after cdata part 
       
   105 		aChunk.Set( aChunk.Left( cdatastart));
       
   106 		aFinalPart.Set( aFinalPart.Mid( cdataend));
       
   107 	}
       
   108 	
       
   109 	// -----------------------------------------------------------------------------
       
   110 	// ParserUtility::RemoveCDataMarks
       
   111 	// -----------------------------------------------------------------------------
       
   112 	//
       
   113 	void RemoveCDataMarksL( TPtrC8& aData)
       
   114 	{
       
   115 		TInt index = aData.Find( KCDataStart);
       
   116 	
       
   117 		User::LeaveIfError( index );
       
   118 		
       
   119 		aData.Set( aData.Mid( index +  KCDataStartLength));
       
   120 		
       
   121 		TInt validIndex = 0;
       
   122 		TInt tempIndex;
       
   123 		
       
   124 		TPtrC8 temp = aData;
       
   125 
       
   126 		while ( KErrNotFound != ( tempIndex = temp.Find( KCDataEnd)))
       
   127 		{
       
   128 			validIndex += tempIndex + KCDataEndLength;
       
   129 			temp.Set( temp.Mid( tempIndex + KCDataEndLength ));
       
   130 		}
       
   131 		
       
   132 		User::LeaveIfError( index );
       
   133 		
       
   134 		aData.Set( aData.Left( validIndex - KCDataEndLength));
       
   135 	}
       
   136 	
       
   137 	TInt LineCounter( TPtrC8& aData)
       
   138 	{
       
   139 		TPtrC8 temp = aData;
       
   140 		TInt rowCount = 0;
       
   141 		TInt index;
       
   142 		
       
   143 		//ascii code 10 is line feed mark
       
   144 		while ( KErrNotFound != ( index = temp.Locate( 10)))
       
   145 		{
       
   146 			rowCount++;
       
   147 			temp.Set( temp.Mid( index + 1 ));
       
   148 		}
       
   149 		
       
   150 		return rowCount;
       
   151 	}
       
   152 
       
   153 }
       
   154 
       
   155 
       
   156 // FORWARD DECLARATIONS
       
   157 // CLASS DECLARATION
       
   158 	
       
   159 
       
   160 // -----------------------------------------------------------------------------
       
   161 // CPolicyParser::CPolicyParser
       
   162 // -----------------------------------------------------------------------------
       
   163 //
       
   164 CPolicyParser::CPolicyParser( CPolicyStorage * aStorage)
       
   165 	: iStorage( aStorage)
       
   166 {
       
   167 	
       
   168 }
       
   169 
       
   170 // -----------------------------------------------------------------------------
       
   171 // CPolicyParser::~CPolicyParser
       
   172 // -----------------------------------------------------------------------------
       
   173 //
       
   174 
       
   175 CPolicyParser::~CPolicyParser()
       
   176 {
       
   177 	delete iElementStack;
       
   178 	delete iParser;
       
   179 }
       
   180 
       
   181 // -----------------------------------------------------------------------------
       
   182 // CPolicyParser::NewL
       
   183 // -----------------------------------------------------------------------------
       
   184 //
       
   185 
       
   186 CPolicyParser* CPolicyParser::NewL( CPolicyStorage * aStorage)
       
   187 {
       
   188 	//2nd phase constructor
       
   189 	CPolicyParser * self = new (ELeave) CPolicyParser( aStorage);
       
   190 	
       
   191 	CleanupStack::PushL( self);
       
   192 	self->ConstructL();
       
   193 	CleanupStack::Pop( self);
       
   194 	
       
   195 	return self;
       
   196 }
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CPolicyParser::ConstructL()
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 
       
   203 void CPolicyParser::ConstructL()
       
   204 {
       
   205 	//2nd phase constructor
       
   206 	iElementStack = new (ELeave)CStack<CElementBase, EFalse>;
       
   207 	iParser = Xml::CParser::NewL( _L8( "text/xml"), *this );	
       
   208 }
       
   209 
       
   210 // -----------------------------------------------------------------------------
       
   211 // CPolicyParser::ParseXACMLObjects()
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 
       
   215 CElementBase * CPolicyParser::ParseXACMLObjects( TInt& aError, const TDesC8 &aXACML, TDes8 &aReturnText)
       
   216 {
       
   217 	//parsing for XACML objects
       
   218 	//Set parsing properties
       
   219 	iValidCharacterSet = EFalse;		
       
   220 	iErrorHandling = ETrue;
       
   221 	iLanguage = EXACML;
       
   222 	
       
   223 	iElementStack->Reset();
       
   224 	iStorage->ResetRealIdValidTest();
       
   225 		
       
   226 	iActiveElement = NULL;		
       
   227 	iReturnText = ParserErrors::ParsingOk;	
       
   228 
       
   229 	//actual parsing....
       
   230 	TRAP( aError, ParseL( aXACML));
       
   231 	
       
   232 	//In error case delete root element...
       
   233 	if ( aError != KErrNone )
       
   234 	{
       
   235 		delete iRootElement;
       
   236 		iRootElement = NULL;
       
   237 	}
       
   238 	
       
   239 	iStorage->ResetRealIdValidTest();
       
   240 
       
   241 	aReturnText  = iReturnText;
       
   242 	
       
   243 	
       
   244 	return iRootElement;
       
   245 }	
       
   246 
       
   247 // -----------------------------------------------------------------------------
       
   248 // CPolicyParser::ParseL()
       
   249 // -----------------------------------------------------------------------------
       
   250 //
       
   251 
       
   252 void CPolicyParser::ParseL( const TDesC8 &aXACML)
       
   253 {
       
   254 	//reset line counter and initialize XML-parser
       
   255 	iActiveLine = 0;
       
   256 	iParser->ParseBeginL();
       
   257 
       
   258 	//Max size of chunk (max text length, which go once to parser)
       
   259 	const TInt KMaxChunkLength = 1000;
       
   260 	
       
   261 	TPtrC8 xacmlDescription = aXACML;
       
   262 	TPtrC8 chunk;
       
   263 	TInt length = KMaxChunkLength < xacmlDescription.Length() ? KMaxChunkLength : xacmlDescription.Length();
       
   264 
       
   265 	do
       
   266 	{
       
   267 		//max text, which go to parser is one line or KMaxChunkLength. Counter tracks line, where parsing is going
       
   268 		iActiveLine++;
       
   269 		//Find line feed mark (asciicode 10)
       
   270 		TInt index = xacmlDescription.Locate(10);
       
   271 		
       
   272 		if ( index != KErrNotFound)
       
   273 		{
       
   274 			length = index + 1;
       
   275 		}
       
   276 		
       
   277 		//set chunk pointer
       
   278 		chunk.Set( xacmlDescription.Left(length));
       
   279 		TPtrC8 cdata;
       
   280 
       
   281 		if ( ParserUtility::ContainsCDataField( chunk))
       
   282 		{
       
   283 			//cdata mark indicated in chunk, remove cdata area from chunk, 
       
   284 			ParserUtility::ReadCDataAreaL( cdata, chunk, xacmlDescription);
       
   285 			
       
   286 			if ( iLanguage == EXACML)
       
   287 			{
       
   288 				iActiveLine += ParserUtility::LineCounter( cdata);
       
   289 			}
       
   290 		}
       
   291 		else
       
   292 		{
       
   293 			//set remaining XACML description to xacmlDescription
       
   294 			xacmlDescription.Set( xacmlDescription.Mid(length));			
       
   295 		}		
       
   296 	
       
   297 		
       
   298 		//'|' and '~' are not allowed in policy system...
       
   299 		if ( iLanguage == EXACML && (chunk.Locate('|') != KErrNotFound || chunk.Locate('~') != KErrNotFound))
       
   300 		{
       
   301 			HandleErrorL( ParserErrors::InvalidMark, ParserErrors::InvalidMarks); 
       
   302 		}
       
   303 	
       
   304 		//drive description to parser	
       
   305 		iParser->ParseL( chunk);
       
   306 		
       
   307 		//in cdata case call directly OnContent
       
   308 		if ( cdata.Length())
       
   309 		{
       
   310 			TInt err = KErrNotFound; 
       
   311 			OnContentL( cdata, err);
       
   312 		}
       
   313 	
       
   314 		length = KMaxChunkLength < xacmlDescription.Length() ? KMaxChunkLength : xacmlDescription.Length();
       
   315 	} while ( length);
       
   316 
       
   317 	//close parser
       
   318 	iParser->ParseEndL();
       
   319 }
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // CPolicyParser::ParseL()
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 
       
   326 TInt CPolicyParser::ParseNativeObjects( CElementBase * aSeedElement, const TDesC8 &aNative, TBool aAddToEditableCache)
       
   327 {
       
   328 	//parsing for native objects
       
   329 	//set parsing properties
       
   330 	iValidCharacterSet = ETrue;
       
   331 	iErrorHandling = EFalse;
       
   332 	iLanguage = ENative;		
       
   333 	iElementStack->Reset();
       
   334 	iAddToEditableCache = aAddToEditableCache;
       
   335 	
       
   336 	//seed element is given by function caller
       
   337 	iActiveElement = aSeedElement;		
       
   338 
       
   339 	//parsing
       
   340 	TRAPD( err, ParseL( aNative));
       
   341 	
       
   342 	return err;	
       
   343 }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // CPolicyParser::SetLineOffset()
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 
       
   350 void CPolicyParser::SetLineOffset( TInt aLine)
       
   351 {
       
   352 	iLineOffset = aLine;
       
   353 }
       
   354 
       
   355 
       
   356 // -----------------------------------------------------------------------------
       
   357 // CPolicyParser::HandleErrorL()
       
   358 // -----------------------------------------------------------------------------
       
   359 //
       
   360 void CPolicyParser::HandleErrorL( const TDesC8 &aText)
       
   361 	{
       
   362 	//if error handling is on....
       
   363 	if ( iErrorHandling )
       
   364 		{
       
   365 		//parse error text
       
   366 		iReturnText.Copy( _L8("(Line "));
       
   367 		iReturnText.AppendNum( iActiveLine + iLineOffset);
       
   368 		iReturnText.Append( _L8(") "));
       
   369 		iReturnText.Append( aText);
       
   370 		RDEBUG8_2("XACML parser error: %S", &iReturnText);
       
   371 		}
       
   372 
       
   373 	User::Leave( KErrParser );
       
   374 	}
       
   375 
       
   376 // -----------------------------------------------------------------------------
       
   377 // CPolicyParser::HandleErrorL()
       
   378 // -----------------------------------------------------------------------------
       
   379 //
       
   380 
       
   381 void CPolicyParser::HandleErrorL( const TDesC8 &aText, const TDesC8 &aErrorElement)
       
   382 {
       
   383 	//parse error text
       
   384 
       
   385 	TBuf8<KMaxReturnMessageLength> returnText;
       
   386 	
       
   387 	const TInt KErrorMsgLength = 20;
       
   388 	
       
   389 	if ( (aText.Length() + aErrorElement.Length() + KErrorMsgLength) < KMaxReturnMessageLength) 
       
   390 	{
       
   391 		returnText = aText;
       
   392 		returnText.Append(_L(": "));
       
   393 		returnText.Append( aErrorElement);
       
   394 	}
       
   395 	
       
   396 		
       
   397 	HandleErrorL( returnText); 
       
   398 }
       
   399 
       
   400 // -----------------------------------------------------------------------------
       
   401 // CPolicyParser::HandleErrorL()
       
   402 // -----------------------------------------------------------------------------
       
   403 //
       
   404 
       
   405 void CPolicyParser::HandleErrorL( const TAny * aPointer, const TDesC8 &aError, const TDesC8 &aErrorElement)
       
   406 {
       
   407 	if ( aPointer != NULL)
       
   408 	{
       
   409 		HandleErrorL( aError, aErrorElement);
       
   410 	}
       
   411 }
       
   412 
       
   413 // -----------------------------------------------------------------------------
       
   414 // CPolicyParser::HandleNativeErrorL()
       
   415 // -----------------------------------------------------------------------------
       
   416 //
       
   417 
       
   418 void CPolicyParser::HandleNativeErrorL( TInt /*aError*/)
       
   419 {
       
   420 	//When parsing native objects, error messages are not needed
       
   421 	User::Leave( KErrNativeParser);
       
   422 }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // CPolicyParser::Language()
       
   426 // -----------------------------------------------------------------------------
       
   427 //
       
   428 
       
   429 TLanguageSelector CPolicyParser::Language()
       
   430 {
       
   431 	return iLanguage;
       
   432 }
       
   433 
       
   434 // -----------------------------------------------------------------------------
       
   435 // CPolicyParser::CreateIdElementsL()
       
   436 // -----------------------------------------------------------------------------
       
   437 //
       
   438 
       
   439 void CPolicyParser::CreateIdElementsL( const TDesC8& aIdString )
       
   440 {
       
   441 #ifndef __POLICY_BASE_CREATOR_TOOL
       
   442 
       
   443 	TPtrC8 ptr( aIdString);
       
   444 	TUint32 policySystemid(0);
       
   445 	TBool atLeastOneId = EFalse;
       
   446 		
       
   447 	//parse from id string ids, which belongs to current component. 	
       
   448 	while ( ptr[0] == '|')
       
   449 	{
       
   450 		//remove delimiter
       
   451 		ptr.Set( ptr.Mid(1));
       
   452 		
       
   453 		//find second delimiter
       
   454 		TInt index = ptr.Locate('|');
       
   455 		
       
   456 		TPtrC8 elementId( ptr);
       
   457 		
       
   458 		//if second delimiter found set correct length for elementId, otherwise elementId length is allready valid
       
   459 		if ( index != KErrNotFound)
       
   460 		{
       
   461 			elementId.Set( ptr.Left( index));
       
   462 			ptr.Set( ptr.Mid( index));
       
   463 		}
       
   464 			
       
   465 		//read element id to TUint32 variable (policySystemid)
       
   466 		TLex8 lex( elementId);
       
   467 		lex.Val( policySystemid, EDecimal);		
       
   468 
       
   469 		CElementBase * element = 0;
       
   470 	
       
   471 		if ( iAddToEditableCache )
       
   472 		{
       
   473 			element = iStorage->GetEditableElementL( policySystemid);
       
   474 		}
       
   475 		else
       
   476 		{
       
   477 			element = iStorage->GetElementL( policySystemid);
       
   478 		}
       
   479 	
       
   480 		//add id element (element with id) to active element
       
   481 		if ( element )
       
   482 		{
       
   483 			iActiveElement->AddIdElementL( element);
       
   484 		}
       
   485 		else
       
   486 		{
       
   487 			HandleNativeErrorL( KErrParser);
       
   488 		}	
       
   489 		
       
   490 		//at least one element must be found
       
   491 		atLeastOneId = ETrue;
       
   492 	} 
       
   493 	
       
   494 	if ( !atLeastOneId)
       
   495 	{
       
   496 		HandleNativeErrorL( KErrParser);
       
   497 	}
       
   498 	
       
   499 #endif //__POLICY_BASE_CREATOR_TOOL
       
   500 }
       
   501 
       
   502 // -----------------------------------------------------------------------------
       
   503 // CPolicyParser::OnStartDocumentL()
       
   504 // -----------------------------------------------------------------------------
       
   505 //
       
   506 void CPolicyParser::OnStartDocumentL(const Xml::RDocumentParameters& aDocParam, TInt /*aErrorCode*/)
       
   507 {
       
   508 	if ( aDocParam.CharacterSetName().DesC() == PolicyLanguage::XACML::CharacterSetUTF8)
       
   509 	{
       
   510 		iValidCharacterSet = ETrue;	
       
   511 	}
       
   512 }
       
   513 
       
   514 // -----------------------------------------------------------------------------
       
   515 // CPolicyParser::OnEndDocumentL()
       
   516 // -----------------------------------------------------------------------------
       
   517 //	
       
   518 void CPolicyParser::OnEndDocumentL(TInt /*aErrorCode*/)
       
   519 {
       
   520 }
       
   521 
       
   522 // -----------------------------------------------------------------------------
       
   523 // CPolicyParser::OnStartElementL()
       
   524 // -----------------------------------------------------------------------------
       
   525 //		
       
   526 void CPolicyParser::OnStartElementL(const Xml::RTagInfo& aElement, const Xml::RAttributeArray& aAttributes, TInt /*aErrorCode*/)
       
   527 {
       
   528 	//Debug variables
       
   529 	const TDesC8& prefix( aElement.Prefix().DesC());
       
   530 	const TDesC8& uri(aElement.Uri().DesC());
       
   531 	//Debug variables
       
   532 	
       
   533 	//Set active element name (used in error handling)
       
   534   	iActiveElementName.Set( aElement.LocalName().DesC());
       
   535   	TPtrC8 elementName = iActiveElementName;
       
   536   	
       
   537   	//if content is XACML, convert it to native language
       
   538   	if ( iLanguage == EXACML )
       
   539   	{
       
   540 		elementName.Set( ConvertElementNamesL( iActiveElementName));		
       
   541   	}
       
   542   	
       
   543   	TBool createNewElement = ETrue;
       
   544   	if ( iActiveElement )
       
   545   	{
       
   546  		//When activeelement is created (ENotLoaded state) and stack size is 0, parser
       
   547  		//assumes that activeelement is seed element and there is no need to create new elelent
       
   548   		if ((iActiveElement->iElementState == ENotLoadedEditableElement || 
       
   549   			 iActiveElement->iElementState == ENotLoaded ) && iElementStack->Count() == 0)
       
   550   		{
       
   551   			//element must have valid type
       
   552   			if ( !iActiveElement->IdentificateElement( elementName)) 
       
   553   			{
       
   554   				HandleNativeErrorL( KErrParser);
       
   555   			}
       
   556   			createNewElement = EFalse;
       
   557   		}
       
   558   	}
       
   559   	
       
   560   	//Identifie type and create new element
       
   561   	CElementBase * element( NULL);
       
   562    	if ( createNewElement )
       
   563    	{
       
   564 		if ( CAttributeValue::IdentificateType( elementName) )
       
   565 		{
       
   566 	 		element = CAttributeValue::NewL();
       
   567  		} else   
       
   568 		if ( CSubjectAttributeDesignator::IdentificateType( elementName) )
       
   569 		{
       
   570  			element = CSubjectAttributeDesignator::NewL();
       
   571 		} else
       
   572 		if ( CActionAttributeDesignator::IdentificateType( elementName) )
       
   573 		{
       
   574  			element = CActionAttributeDesignator::NewL();
       
   575 		} else
       
   576 		if ( CResourceAttributeDesignator::IdentificateType( elementName) )
       
   577 		{
       
   578  			element = CResourceAttributeDesignator::NewL();
       
   579 		} else
       
   580 		if ( CEnvironmentAttributeDesignator::IdentificateType( elementName) )
       
   581 		{
       
   582  			element = CEnvironmentAttributeDesignator::NewL();
       
   583 		} else
       
   584 		if ( CMatchObject::IdentificateType( elementName) )
       
   585 		{
       
   586  			element = CMatchObject::NewL(elementName);
       
   587  		} else
       
   588 		if ( CSubject::IdentificateType( elementName) )
       
   589 		{
       
   590  			element = CSubject::NewL();
       
   591  		} else
       
   592 		if ( CAction::IdentificateType( elementName) )
       
   593 		{
       
   594  			element = CAction::NewL();
       
   595  		} else
       
   596 		if ( CResource::IdentificateType( elementName) )
       
   597 		{
       
   598  			element = CResource::NewL();
       
   599  		} else
       
   600 		if ( CEnvironment::IdentificateType( elementName) )
       
   601 		{
       
   602  			element = CEnvironment::NewL();
       
   603  		} else
       
   604 		if ( CSubjects::IdentificateType( elementName) )
       
   605 		{
       
   606  			element = CSubjects::NewL();
       
   607  		} else
       
   608 		if ( CActions::IdentificateType( elementName) )
       
   609 		{
       
   610  			element = CActions::NewL();
       
   611  		} else
       
   612 		if ( CResources::IdentificateType( elementName) )
       
   613 		{
       
   614  			element = CResources::NewL();
       
   615  		} else
       
   616 		if ( CEnvironments::IdentificateType( elementName) )
       
   617 		{
       
   618  			element = CEnvironments::NewL();
       
   619  		} else
       
   620 		if ( CRule::IdentificateType( elementName) )
       
   621 		{
       
   622  			element = CRule::NewL();
       
   623  		} else
       
   624 		if ( CTarget::IdentificateType( elementName) )
       
   625 		{
       
   626  			element = CTarget::NewL();
       
   627  		} else
       
   628 		if ( CPolicy::IdentificateType( elementName) )
       
   629 		{
       
   630  			element = CPolicy::NewL();
       
   631  		} else
       
   632 		if ( CPolicySet::IdentificateType( elementName) )
       
   633 		{
       
   634  			element = CPolicySet::NewL();
       
   635  		} else
       
   636 		if ( CDescription::IdentificateType( elementName) )
       
   637 		{
       
   638  			element = CDescription::NewL();
       
   639  		} else
       
   640 		if ( CApply::IdentificateType( elementName) )
       
   641 		{
       
   642  			element = CApply::NewL();
       
   643  		} else
       
   644 		if ( CCondition::IdentificateType( elementName) )
       
   645 		{
       
   646  			element = CCondition::NewL();
       
   647 		} 		
       
   648  		else
       
   649  		{
       
   650  			HandleErrorL( ParserErrors::InvalidElement, iActiveElementName);
       
   651  		}
       
   652  		
       
   653  		//set element to correct state in Native mode
       
   654  		if ( iLanguage == ENative)
       
   655  		{
       
   656  			element->iElementState = iAddToEditableCache ? EEditableCacheElement : ECacheElement;
       
   657  		}
       
   658    	}
       
   659    	else
       
   660    	{
       
   661    		//and if active element is already created use it....
       
   662    		element = iActiveElement;
       
   663    	}
       
   664  	 	
       
   665  	 //cleanup...
       
   666  	CleanupStack::PushL( element);
       
   667  	 	
       
   668  	 //search eleement attributes
       
   669 	for ( TInt i = 0; i < aAttributes.Count(); i++)
       
   670 	{
       
   671 		Xml::RAttribute attribute( aAttributes[i]);
       
   672 		
       
   673 		//DEBUG VARIABLES
       
   674 		const TDesC8& prefixx( attribute.Attribute().Prefix().DesC());
       
   675 		const TDesC8& urii(attribute.Attribute().Uri().DesC());
       
   676   		const TDesC8& elementNamee( attribute.Attribute().LocalName().DesC());
       
   677 		//DEBUG VARIABLES
       
   678 
       
   679 		TPtrC8 convertedName = attribute.Attribute().LocalName().DesC();
       
   680 		TPtrC8 convertedValue = attribute.Value().DesC();
       
   681 	  	
       
   682 		//if XACML used, convert names to native language
       
   683 	  	if ( iLanguage == EXACML )
       
   684 	  	{
       
   685 			convertedName.Set( ConvertAttributesL( attribute.Attribute().LocalName().DesC()));
       
   686 			convertedValue.Set( ConvertValues( EXACML, attribute.Value().DesC()));
       
   687   		}
       
   688 		
       
   689 		//and add attributes to element
       
   690 		element->AddAttributeL( this, convertedName, convertedValue );			
       
   691 	}
       
   692 
       
   693 	//add element to element stack
       
   694 	iElementStack->PushL( iActiveElement);
       
   695 	
       
   696 	//and if new element created
       
   697 	if ( createNewElement )
       
   698 	{
       
   699 		if ( iActiveElement != NULL)	
       
   700 		{	
       
   701 			//if active element exist add element to active element...
       
   702 			iActiveElement->AddElementL( this, element);
       
   703 		}
       
   704 		else
       
   705 		{
       
   706 			//...otherwise add element to root
       
   707 			iRootElement = element;
       
   708 		}
       
   709 		
       
   710 		//current element is active element for next element
       
   711 		iActiveElement = element;
       
   712 	}
       
   713 	
       
   714 	//cleanup: element
       
   715 	CleanupStack::Pop( element);
       
   716 }
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CPolicyParser::OnEndElementL()
       
   720 // -----------------------------------------------------------------------------
       
   721 //		
       
   722 	
       
   723 void CPolicyParser::OnEndElementL(const Xml::RTagInfo& aElement, TInt /*aErrorCode*/)
       
   724 {
       
   725 	//set active element name
       
   726 	iActiveElementName.Set( aElement.LocalName().DesC());
       
   727 	TPtrC8 elementName( iActiveElementName);	
       
   728 	
       
   729 	
       
   730 	//if XACML parsing, convert name to native language
       
   731 	if ( iLanguage == EXACML)
       
   732 	{
       
   733 		elementName.Set( ConvertElementNamesL( iActiveElementName));
       
   734 	}
       
   735 	
       
   736 	//Check is end stack correct
       
   737    	if ( !iActiveElement->IdentificateElement( elementName))
       
   738    	{
       
   739    		HandleErrorL( ParserErrors::InvalidElement, aElement.LocalName().DesC());	
       
   740    	}
       
   741    
       
   742    	//when parsing XACML make validy check for element... 
       
   743    	if ( iLanguage == EXACML)
       
   744    	{
       
   745 	  	if ( !iActiveElement->ValidElement() )
       
   746 	   	{
       
   747    			HandleErrorL( ParserErrors::InvalidElement, iActiveElementName);
       
   748 	   	}
       
   749    	}
       
   750    
       
   751     //previous active element from stack
       
   752 	iActiveElement = iElementStack->Pop();
       
   753 }
       
   754 	
       
   755 // -----------------------------------------------------------------------------
       
   756 // CPolicyParser::OnContentL()
       
   757 // -----------------------------------------------------------------------------
       
   758 //		
       
   759 	
       
   760 void CPolicyParser::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/)
       
   761 {
       
   762 	//activename....
       
   763 	iActiveElementName.Set( aBytes);
       
   764 
       
   765 	TPtrC8 ptr = aBytes;
       
   766 
       
   767 	//remove tabs, spaces, line feeds and so on
       
   768 	ptr.Set( aBytes);
       
   769 	if ( ptr.Length() == 1 && (ptr[0] == 9 || ptr[0] == 13 || ptr[0] == 10 || ptr[0] == 32))
       
   770 	{
       
   771 		//do nothing
       
   772 	}
       
   773 	else
       
   774 	{
       
   775 		//remove extra marks before id check
       
   776 		//from start
       
   777 		while ( ptr[0] == 9 || ptr[0] == 13 || ptr[0] == 10 || ptr[0] == 32)
       
   778 		{
       
   779 		
       
   780 			ptr.Set( ptr.Mid(1));	
       
   781 			if ( ptr.Length() == 0) 
       
   782 			{
       
   783 				break;
       
   784 			}
       
   785 		}
       
   786 
       
   787 		//from end
       
   788 		TInt index = ptr.Length() - 1;
       
   789 		if ( index >= 0 )
       
   790 		{
       
   791 			while ( ptr[ index] == 9 || ptr[ index] == 13 || ptr[ index] == 10 || ptr[ index] == 32)
       
   792 			{
       
   793 				ptr.Set( ptr.Ptr(), index);	
       
   794 				if ( ptr.Length() == 0) 
       
   795 				{
       
   796 					break;
       
   797 				}
       
   798 			
       
   799 				index--;
       
   800 			}
       
   801 		}
       
   802 
       
   803 		if ( ptr.Length() > 0 )
       
   804 		{
       
   805 			//if delimiter found, element content contains element ids, which belong to element
       
   806 			if ( ptr[0] == KMessageDelimiterChar)
       
   807 			{
       
   808 				//create ID-elements 
       
   809 				CreateIdElementsL( ptr);
       
   810 			}
       
   811 			else
       
   812 			{
       
   813 				//or add element content
       
   814 				iActiveElement->AddContentL( this, ptr);
       
   815 			}
       
   816 		}
       
   817 	}
       
   818 
       
   819 }
       
   820 
       
   821 // -----------------------------------------------------------------------------
       
   822 // CPolicyParser::SetExternalIdChecked()
       
   823 // -----------------------------------------------------------------------------
       
   824 //
       
   825 
       
   826 void CPolicyParser::SetExternalIdChecked( TAllowedExternalIdConflicts aCheckerState)
       
   827 {
       
   828 	iCheckerState = aCheckerState;
       
   829 }
       
   830 
       
   831 // -----------------------------------------------------------------------------
       
   832 // CPolicyParser::SetExternalIdChecked()
       
   833 // -----------------------------------------------------------------------------
       
   834 //
       
   835 
       
   836 void CPolicyParser::CheckExternalIdL( const HBufC8 * iExternalId)
       
   837 {
       
   838 	//make external id check only when parsing XACML
       
   839 	if ( iLanguage == EXACML && iCheckerState != KNoExternalIdCheck)
       
   840 	{
       
   841 		if ( !iStorage->IsRealIdValidL( *iExternalId))
       
   842 		{
       
   843 			if ( !( iCheckerState == KSameExternalIdAllowedForRoot && iElementStack->Count() == 0 ))
       
   844 			{
       
   845 				HandleErrorL( ManagementErrors::IdAlreadyExist, *iExternalId);
       
   846 			}
       
   847 		}
       
   848 	}
       
   849 }
       
   850 
       
   851 // -----------------------------------------------------------------------------
       
   852 // CPolicyParser::ActiveElementName()
       
   853 // -----------------------------------------------------------------------------
       
   854 //
       
   855 
       
   856 TDesC8& CPolicyParser::ActiveElementName()
       
   857 {
       
   858 	return iActiveElementName;
       
   859 }
       
   860 
       
   861 // -----------------------------------------------------------------------------
       
   862 // CPolicyParser::CheckCompiningAlgorithmsL()
       
   863 // -----------------------------------------------------------------------------
       
   864 //
       
   865 void CPolicyParser::CheckCompiningAlgorithmsL( TNativeElementTypes aType, const TDesC8& aAlgorithmId )
       
   866 {
       
   867 	//check only when parsinf XACML
       
   868 	if ( iLanguage == EXACML)
       
   869 	{
       
   870 		if ( aAlgorithmId == PolicyLanguage::NativeLanguage::CombiningAlgorithms::RuleDenyOverrides ||
       
   871 			 aAlgorithmId == PolicyLanguage::NativeLanguage::CombiningAlgorithms::RulePermitOverrides)
       
   872 		{
       
   873 			if ( aType != EPolicy)
       
   874 			{
       
   875 				HandleErrorL( ParserErrors::InvalidValue, aAlgorithmId);
       
   876 			}
       
   877 		}
       
   878 		else
       
   879 		if ( aAlgorithmId == PolicyLanguage::NativeLanguage::CombiningAlgorithms::PolicyDenyOverrides ||
       
   880 			 aAlgorithmId == PolicyLanguage::NativeLanguage::CombiningAlgorithms::PolicyPermitOverrides)
       
   881 		{
       
   882 			if ( aType != EPolicySet)
       
   883 			{
       
   884 				HandleErrorL( ParserErrors::InvalidValue, aAlgorithmId);
       
   885 			}
       
   886 		}
       
   887 		else
       
   888 		{
       
   889 			HandleErrorL( ParserErrors::InvalidValue, aAlgorithmId);
       
   890 		}
       
   891 	}
       
   892 }
       
   893 
       
   894 // -----------------------------------------------------------------------------
       
   895 // CPolicyParser::CheckFunctionIdL()
       
   896 // -----------------------------------------------------------------------------
       
   897 //
       
   898 
       
   899 void CPolicyParser::CheckFunctionIdL( const TNativeElementTypes& aType, const TDesC8& aFunctionId )
       
   900 {
       
   901 	if ( iLanguage == EXACML)
       
   902 	{
       
   903 		//these functions are valid for apply-component
       
   904 		if ( aType == EApply)
       
   905 		{
       
   906 			if (!( aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionAnd ||
       
   907    				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionNot ||
       
   908 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionOr ||
       
   909 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionCertificatedSession ||
       
   910 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionRuleTargetStructure ||
       
   911 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionUserAcceptCorpPolicy ||
       
   912 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionBooleanEqualId ||	
       
   913 				   aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionStringEqualId ))
       
   914 			{
       
   915 				HandleErrorL( ParserErrors::InvalidValue, aFunctionId );
       
   916 			}
       
   917 		}	//and these are valid also for other elements (match elements in practice)
       
   918 		else if	(!(aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionStringEqualId || 
       
   919 			  	aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionBooleanEqualId ||	
       
   920 			  	aFunctionId == PolicyLanguage::NativeLanguage::Functions::FunctionUserAcceptCorpPolicy ||
       
   921 			  	aFunctionId == PolicyLanguage::NativeLanguage::Functions::TrustedRoleMatch ||
       
   922 			  	aFunctionId == PolicyLanguage::NativeLanguage::Functions::TrustedSubjectMatch))
       
   923 		{
       
   924 			HandleErrorL( ParserErrors::InvalidValue, aFunctionId );
       
   925 		}
       
   926 	}
       
   927 }
       
   928 
       
   929 // -----------------------------------------------------------------------------
       
   930 // CPolicyParser::CheckEffectL()
       
   931 // -----------------------------------------------------------------------------
       
   932 //
       
   933 
       
   934 void CPolicyParser::CheckEffectL( const TDesC8& aEffect )
       
   935 {
       
   936 	if ( iLanguage == EXACML)
       
   937 	{
       
   938 		if (!(aEffect == PolicyLanguage::NativeLanguage::Rule::Deny ||
       
   939 			 aEffect == PolicyLanguage::NativeLanguage::Rule::Permit ))
       
   940 		{
       
   941 			HandleErrorL( ParserErrors::InvalidValue, aEffect );
       
   942 		}
       
   943 	}
       
   944 }
       
   945 
       
   946 // -----------------------------------------------------------------------------
       
   947 // CPolicyParser::CheckDataTypeL()
       
   948 // -----------------------------------------------------------------------------
       
   949 //
       
   950 
       
   951 void CPolicyParser::CheckDataTypeL( const TDesC8& aDataType )
       
   952 {
       
   953 	if ( iLanguage == EXACML)
       
   954 	{
       
   955 		if (!(aDataType == PolicyLanguage::NativeLanguage::AttributeValues::StringDataType || 
       
   956 			  aDataType == PolicyLanguage::NativeLanguage::AttributeValues::BooleanDataType	))
       
   957 		{
       
   958 			HandleErrorL( ParserErrors::InvalidValue, aDataType );
       
   959 		}
       
   960 	}
       
   961 }
       
   962 
       
   963 // -----------------------------------------------------------------------------
       
   964 // CPolicyParser::OnStartPrefixMappingL()
       
   965 // -----------------------------------------------------------------------------
       
   966 //
       
   967 void CPolicyParser::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/)
       
   968 {
       
   969 
       
   970 }
       
   971 	
       
   972 // -----------------------------------------------------------------------------
       
   973 // CPolicyParser::OnEndPrefixMappingL()
       
   974 // -----------------------------------------------------------------------------
       
   975 //    
       
   976 void CPolicyParser::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/)
       
   977 {
       
   978    
       
   979 }
       
   980 
       
   981 // -----------------------------------------------------------------------------
       
   982 // CPolicyParser::OnIgnorableWhiteSpaceL()
       
   983 // -----------------------------------------------------------------------------
       
   984 //	
       
   985 void CPolicyParser::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/, TInt /*aErrorCode*/)
       
   986    {
       
   987  
       
   988 }
       
   989 
       
   990 // -----------------------------------------------------------------------------
       
   991 // CPolicyParser::OnSkippedEntityL()
       
   992 // -----------------------------------------------------------------------------
       
   993 //	
       
   994 void CPolicyParser::OnSkippedEntityL(const RString& /*aName*/, TInt /*aErrorCode*/)
       
   995 {
       
   996    	
       
   997 }
       
   998 
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CPolicyParser::OnProcessingInstructionL()
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //	
       
  1004 void CPolicyParser::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/)
       
  1005 {
       
  1006    	
       
  1007 }
       
  1008 
       
  1009 // -----------------------------------------------------------------------------
       
  1010 // CPolicyParser::OnError()
       
  1011 // -----------------------------------------------------------------------------
       
  1012 //	
       
  1013 void CPolicyParser::OnError(TInt /*aErrorCode*/)
       
  1014 	{
       
  1015    	// we need to leave here because Policy Engine traps parser errors, even though
       
  1016    	// this function does not have L in it's name.
       
  1017    	HandleErrorL( ParserErrors::SyntaxError );
       
  1018 	}
       
  1019 
       
  1020 // -----------------------------------------------------------------------------
       
  1021 // CPolicyParser::GetExtendedInterface()
       
  1022 // -----------------------------------------------------------------------------
       
  1023 //	
       
  1024 TAny* CPolicyParser::GetExtendedInterface(const TInt32 /*aUid*/)
       
  1025 	{
       
  1026 	
       
  1027 	return NULL;		
       
  1028 	}
       
  1029 
       
  1030 // -----------------------------------------------------------------------------
       
  1031 // CPolicyParser::ConvertElementNamesL()
       
  1032 // -----------------------------------------------------------------------------
       
  1033 //	
       
  1034 const TDesC8& CPolicyParser::ConvertElementNamesL( const TDesC8& aElementName )
       
  1035 {
       
  1036 	using namespace PolicyLanguage;
       
  1037 	
       
  1038 	//Conver name from XACML to native language (maybe array structure should be used to avoid editing when values is added)
       
  1039 	if ( AttributeDesignators::SubjectAttributeDesignator[ EXACML ] == aElementName ) return AttributeDesignators::SubjectAttributeDesignator[ ENative];
       
  1040 	if ( AttributeDesignators::ActionAttributeDesignator[ EXACML ] == aElementName ) return AttributeDesignators::ActionAttributeDesignator[ ENative];
       
  1041 	if ( AttributeDesignators::ResourceAttributeDesignator[ EXACML ] == aElementName ) return AttributeDesignators::ResourceAttributeDesignator[ ENative];
       
  1042 	if ( AttributeDesignators::EnvironmentAttributeDesignator[ EXACML ] == aElementName ) return AttributeDesignators::EnvironmentAttributeDesignator[ ENative];
       
  1043 	
       
  1044 	if ( AttributeValues::AttributeValue[ EXACML ] == aElementName ) return AttributeValues::AttributeValue[ ENative];
       
  1045 	
       
  1046 	if ( MatchObject::SubjectMatch[ EXACML ] == aElementName ) return MatchObject::SubjectMatch[ ENative];
       
  1047 	if ( MatchObject::ActionMatch[ EXACML ] == aElementName ) return MatchObject::ActionMatch[ ENative];
       
  1048 	if ( MatchObject::EnvironmentMatch[ EXACML ] == aElementName ) return MatchObject::EnvironmentMatch[ ENative];
       
  1049 	if ( MatchObject::ResourceMatch[ EXACML ] == aElementName ) return MatchObject::ResourceMatch[ ENative];
       
  1050 	
       
  1051 	if ( MatchContainers::Subject[ EXACML ] == aElementName ) return MatchContainers::Subject[ ENative];
       
  1052 	if ( MatchContainers::Subjects[ EXACML ] == aElementName ) return MatchContainers::Subjects[ ENative];
       
  1053 	if ( MatchContainers::Action[ EXACML ] == aElementName ) return MatchContainers::Action[ ENative];
       
  1054 	if ( MatchContainers::Actions[ EXACML ] == aElementName ) return MatchContainers::Actions[ ENative];
       
  1055 	if ( MatchContainers::Resource[ EXACML ] == aElementName ) return MatchContainers::Resource[ ENative];
       
  1056 	if ( MatchContainers::Resources[ EXACML ] == aElementName ) return MatchContainers::Resources[ ENative];
       
  1057 	if ( MatchContainers::Environment[ EXACML ] == aElementName ) return MatchContainers::Environment[ ENative];
       
  1058 	if ( MatchContainers::Environments[ EXACML ] == aElementName ) return MatchContainers::Environments[ ENative];
       
  1059 
       
  1060 	if ( Rule::Rule[ EXACML ] == aElementName ) return Rule::Rule[ ENative];
       
  1061 	if ( Rule::Target[ EXACML ] == aElementName ) return Rule::Target[ ENative];
       
  1062 	if ( PolicySet::PolicySet[ EXACML ] == aElementName ) return PolicySet::PolicySet[ ENative];
       
  1063 	if ( Policy::Policy[ EXACML ] == aElementName ) return Policy::Policy[ ENative];
       
  1064 	
       
  1065 	if ( Expressions::Apply[ EXACML ] == aElementName ) return Expressions::Apply[ ENative];
       
  1066 	if ( Expressions::Condition[ EXACML ] == aElementName ) return Expressions::Condition[ ENative];
       
  1067 
       
  1068 	if ( Description::Description[ EXACML ] == aElementName ) return Description::Description[ ENative];
       
  1069 
       
  1070 	HandleErrorL( ParserErrors::InvalidElement, aElementName);
       
  1071 
       
  1072 	return aElementName;
       
  1073 }
       
  1074 
       
  1075 // -----------------------------------------------------------------------------
       
  1076 // CPolicyParser::ConvertAttributesL()
       
  1077 // -----------------------------------------------------------------------------
       
  1078 //
       
  1079 const TDesC8& CPolicyParser::ConvertAttributesL( const TDesC8& aType )
       
  1080 {
       
  1081 	using namespace PolicyLanguage;
       
  1082 	
       
  1083 	//Conver name from XACML to native language (maybe array structure should be used to avoid editing when values is added)
       
  1084 	if ( AttributeDesignators::AttributeId[ EXACML ] == aType ) return AttributeDesignators::AttributeId[ ENative];
       
  1085 	if ( AttributeDesignators::DataType[ EXACML ] == aType ) return AttributeDesignators::DataType[ ENative];
       
  1086 	
       
  1087 	if ( AttributeValues::DataType[ EXACML ] == aType ) return AttributeValues::DataType[ ENative];
       
  1088 
       
  1089 	if ( MatchObject::MatchId[ EXACML ] == aType ) return MatchObject::MatchId[ ENative];
       
  1090 	
       
  1091 	if ( Rule::RuleId[ EXACML ] == aType ) return Rule::RuleId[ ENative];
       
  1092 	if ( Rule::Effect[ EXACML ] == aType ) return Rule::Effect[ ENative];
       
  1093 
       
  1094 	if ( Expressions::FunctionId[ EXACML ] == aType ) return Expressions::FunctionId[ ENative];
       
  1095 
       
  1096 	if ( Policy::PolicyId[ EXACML ] == aType ) return Policy::PolicyId[ ENative];
       
  1097 	if ( Policy::RuleCombiningAlgId[ EXACML ] == aType ) return Policy::RuleCombiningAlgId[ ENative];
       
  1098 
       
  1099 	if ( PolicySet::PolicySetId[ EXACML ] == aType ) return PolicySet::PolicySetId[ ENative];
       
  1100 	if ( PolicySet::PolicyCombiningAlgId[ EXACML ] == aType ) return PolicySet::PolicyCombiningAlgId[ ENative];
       
  1101 
       
  1102 	HandleErrorL( ParserErrors::InvalidElement, aType);
       
  1103 
       
  1104 	return aType;
       
  1105 }
       
  1106 
       
  1107 // -----------------------------------------------------------------------------
       
  1108 // CPolicyParser::ConvertValues()
       
  1109 // -----------------------------------------------------------------------------
       
  1110 //
       
  1111 const TDesC8& CPolicyParser::ConvertValues( TLanguageSelector aLanguage, const TDesC8& aValue)
       
  1112 {
       
  1113 	using namespace PolicyLanguage;
       
  1114 
       
  1115 	//Conver name from XACML (or native depends on aLanguage variable) to native (or XACML) language 
       
  1116 	//(maybe array structure should be used to avoid editing when values is added)
       
  1117 	
       
  1118 	//destination langauge, aLanguage is source language
       
  1119 	TLanguageSelector destLang = ENative;
       
  1120 	
       
  1121 	if ( aLanguage == ENative)
       
  1122 	{
       
  1123 		destLang = EXACML;
       
  1124 	}
       
  1125 	
       
  1126 	if ( AttributeValues::StringDataType[ aLanguage ] == aValue ) return AttributeValues::StringDataType[ destLang];
       
  1127 	if ( AttributeValues::BooleanDataType[ aLanguage ] == aValue ) return AttributeValues::BooleanDataType[ destLang];
       
  1128 	if ( AttributeValues::BooleanTrue[ aLanguage ] == aValue ) return AttributeValues::BooleanTrue[ destLang];
       
  1129 	if ( AttributeValues::BooleanFalse[ aLanguage ] == aValue ) return AttributeValues::BooleanFalse[ destLang];
       
  1130 
       
  1131 	if ( Rule::Permit[ aLanguage ] == aValue ) return Rule::Permit[ destLang];
       
  1132 	if ( Rule::Deny[ aLanguage ] == aValue ) return Rule::Deny[ destLang];
       
  1133 
       
  1134 	if ( Functions::TrustedRoleMatch[ aLanguage ] == aValue ) return Functions::TrustedRoleMatch[ destLang];
       
  1135 	if ( Functions::TrustedSubjectMatch[ aLanguage ] == aValue ) return Functions::TrustedSubjectMatch[ destLang];
       
  1136 	if ( Functions::FunctionStringEqualId[ aLanguage ] == aValue ) return Functions::FunctionStringEqualId[ destLang];
       
  1137 	if ( Functions::FunctionBooleanEqualId[ aLanguage ] == aValue ) return Functions::FunctionBooleanEqualId[ destLang];
       
  1138 
       
  1139 	if ( Functions::FunctionOr[ aLanguage ] == aValue ) return Functions::FunctionOr[ destLang];
       
  1140 	if ( Functions::FunctionAnd[ aLanguage ] == aValue ) return Functions::FunctionAnd[ destLang];
       
  1141 	if ( Functions::FunctionAnd[ aLanguage ] == aValue ) return Functions::FunctionAnd[ destLang];
       
  1142 
       
  1143 	if ( Functions::FunctionCertificatedSession[ aLanguage ] == aValue ) return Functions::FunctionCertificatedSession[ destLang];
       
  1144 	if ( Functions::FunctionUserAcceptCorpPolicy[ aLanguage ] == aValue ) return Functions::FunctionUserAcceptCorpPolicy[ destLang];
       
  1145 	if ( Functions::FunctionRuleTargetStructure[ aLanguage ] == aValue ) return Functions::FunctionRuleTargetStructure[ destLang];
       
  1146 
       
  1147 	if ( CombiningAlgorithms::RuleDenyOverrides[ aLanguage ] == aValue ) return CombiningAlgorithms::RuleDenyOverrides[ destLang];
       
  1148 	if ( CombiningAlgorithms::PolicyDenyOverrides[ aLanguage ] == aValue ) return CombiningAlgorithms::PolicyDenyOverrides[ destLang];
       
  1149 	if ( CombiningAlgorithms::RulePermitOverrides[ aLanguage ] == aValue ) return CombiningAlgorithms::RulePermitOverrides[ destLang];
       
  1150 	if ( CombiningAlgorithms::PolicyPermitOverrides[ aLanguage ] == aValue ) return CombiningAlgorithms::PolicyPermitOverrides[ destLang];
       
  1151 	
       
  1152 
       
  1153 	return aValue;
       
  1154 }
       
  1155