policymanagement/policyengine/policyengineserver/inc/ElementBase.h
changeset 0 b497e44ab2fc
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 #ifndef ELEMENT_BASE_HEADER_
       
    20 #define ELEMENT_BASE_HEADER_
       
    21 
       
    22 // INCLUDES
       
    23 
       
    24 #include <e32base.h>
       
    25 
       
    26 #include <PolicyEngineClientServer.h>
       
    27 
       
    28 // CONSTANTS
       
    29 
       
    30 const int KMaxLengthPolicyElementID = 30;
       
    31 const int KNotInElementCache = -1;
       
    32 const int KIdLength = 8;
       
    33 
       
    34 enum TNativeElementTypes
       
    35 {		
       
    36 	EPolicy = 0,
       
    37 	EPolicySet,
       
    38 	ESubjectAttributeDesignator,
       
    39 	EActionAttributeDesignator,
       
    40 	EEnvironmentAttributeDesignator,
       
    41 	EResourceAttributeDesignator,
       
    42 	EAttributeValue,
       
    43 	ESubjectMatch,
       
    44 	EActionMatch,
       
    45 	EResourceMatch,
       
    46 	EEnvironmentMatch,	
       
    47 	ESubject,
       
    48 	EAction,
       
    49 	EResource,
       
    50 	EEnvironment,	
       
    51 	ESubjects,
       
    52 	EActions,
       
    53 	EResources,
       
    54 	EEnvironments,
       
    55 	ETarget,
       
    56 	ERule,
       
    57 	ECondition,
       
    58 	EAttribute,
       
    59 	EDescription,
       
    60 	EApply
       
    61 };
       
    62 
       
    63 
       
    64 enum TElementState
       
    65 {
       
    66 	//Brand-new element. Storage automatically saves also all subelements
       
    67 	ENewElement,
       
    68 	//Element is created (and added into the cache), but its subelements are not loaded
       
    69 	ENotLoaded,
       
    70 	//Element is loaded and added into the cache, subelements are loaded
       
    71 	ECacheElement,
       
    72 	//Element is created (and added into the editable cache), but its subelements are not loaded
       
    73 	ENotLoadedEditableElement,
       
    74 	//Element is loaded and added into the editable cache, subelements are loaded
       
    75 	EEditableCacheElement,
       
    76 	//element is in the editable cache (element is loaded) and contains changes, 
       
    77 	//saved to disk during commit. Recursive save is not possible for EEditedElement!
       
    78 	EEditedElement,
       
    79 	//element is in the editable cache and is deleted from disk (during commit)
       
    80 	EDeletedEditableElement,
       
    81 	//element is in the cache, but disk contains newer version
       
    82 	EDepricated
       
    83 };
       
    84 
       
    85 enum TDecodeMode
       
    86 {
       
    87 	EFullMode,
       
    88 	EIdMode	
       
    89 };
       
    90 
       
    91 enum TSaveType
       
    92 {
       
    93 	EOwnElement,
       
    94 	ESubElement
       
    95 };
       
    96 
       
    97 enum TLanguageSelector
       
    98 {
       
    99 	EXACML = 0,
       
   100 	ENative = 1
       
   101 };
       
   102 
       
   103 enum TMatchResponse
       
   104 {
       
   105 	EDeny = 0,
       
   106 	EPermit,
       
   107 	ENotApplicable,
       
   108 	EIndeterminate,
       
   109 	EMatch,
       
   110 	EUnMatch
       
   111 };
       
   112 
       
   113 _LIT( PolicyParserPanic, "Policy Parser Panic!");
       
   114 _LIT( PolicyExecutionPanic, "Policy execution Panic!");
       
   115 _LIT( PolicyStoragePanic, "Policy storage Panic!");
       
   116 
       
   117 // MACROS
       
   118 // DATA TYPES
       
   119 // FUNCTION PROTOTYPES
       
   120 // FORWARD DECLARATIONS
       
   121 
       
   122 class CElementBase;
       
   123 class TUnionTarget;
       
   124 class CAttributeValue;
       
   125 class CPolicyStorage;
       
   126 class CPolicyParser;
       
   127 class CPolicyProcessor;
       
   128 class CMatchObject;
       
   129 
       
   130 // CLASS DECLARATION
       
   131 
       
   132 
       
   133 
       
   134 
       
   135 namespace ElementHelper
       
   136 {
       
   137 	HBufC8 * DecodeEmptyElement( const TDesC8& aElementName);
       
   138 	CElementBase * CreateNewElementL( const TUint32& aElementId);
       
   139 	TInt CompareElements( CElementBase* const& aElement1, CElementBase* const& aElement2);
       
   140 	TInt XACMLCompare( const TDesC8& aTag, const TPtrC8 aTags[2]);
       
   141 }
       
   142 
       
   143 class TElementContainer
       
   144 {	
       
   145 	public:
       
   146 	CElementBase * iElement;
       
   147 	TBool iDeleteWithElement;
       
   148 };
       
   149 
       
   150 typedef RArray<TElementContainer*> RElementContainer;
       
   151 typedef RArray<TUint32> RIdList;
       
   152 typedef RArray<CMatchObject*> RMatchObjectArray;
       
   153 typedef RArray<CElementBase*> RElementArray;
       
   154 
       
   155 class MElementBase
       
   156 {
       
   157 	public:
       
   158 		virtual void SetId( const TUint32& aElementId) = 0;
       
   159 		
       
   160 		virtual TUint32 GetId() const = 0;
       
   161 		virtual HBufC8 * ExternalId() const = 0;
       
   162 		
       
   163 		virtual TNativeElementTypes ElementType() = 0;
       
   164 		
       
   165 		virtual HBufC8 * DecodeElementL( const TLanguageSelector &aLanguage, const TDecodeMode &aMode) = 0;
       
   166 		virtual HBufC8 * DecodeIdL() = 0;
       
   167 				
       
   168 		//Storage functions
       
   169 		virtual TInt SaveElementL( TBool aRecursive) = 0;
       
   170 		
       
   171 		//Execution functions
       
   172 		virtual TMatchResponse MatchL( CPolicyProcessor* aPolicyProcessor) = 0;
       
   173 		virtual CAttributeValue *  ApplyValueL( CPolicyProcessor* aPolicyProcessor) = 0;
       
   174 		
       
   175 	protected:
       
   176 		virtual void AddIdElementL( CElementBase * aElement) = 0;
       
   177 		
       
   178 	private:	
       
   179 		//Parsing functions
       
   180 		virtual void AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue) = 0;
       
   181 		virtual void AddContentL( CPolicyParser *aParser, const TDesC8& aName) = 0;
       
   182 		virtual void AddElementL( CPolicyParser *aParser, CElementBase * aElement) = 0;			
       
   183 		virtual TBool ValidElement() = 0;
       
   184 };
       
   185 
       
   186 class CElementBase : public CBase, public MElementBase
       
   187 {
       
   188 	public:
       
   189 		CElementBase();
       
   190 		CElementBase( const TUint32& aElementId);
       
   191 		virtual ~CElementBase();
       
   192 	
       
   193 		virtual void SetId( const TUint32& aElementId);
       
   194 		void SetElementType( const TNativeElementTypes& aElementType);
       
   195 		void CreateIdL();
       
   196 		TUint32 GetId() const;
       
   197 		void AddParentIdL( TUint32 iMotherId);
       
   198 		virtual HBufC8 * ExternalId() const;
       
   199 		
       
   200 		
       
   201 		TNativeElementTypes ElementType();
       
   202 		TBool IdentificateElement( const TDesC8& aElementName );
       
   203 		
       
   204 		HBufC8 * DecodeElementL( const  TLanguageSelector &aLanguage, const TDecodeMode &aMode);
       
   205 		HBufC8 * DecodeIdL();
       
   206 		const TDesC8 & SelectCorrectValue( const TLanguageSelector &aLanguage, const TDesC8& aOriginalValue ) const;
       
   207 
       
   208 		TInt ElementCount();
       
   209 		CElementBase * Element( TInt aIndex);
       
   210 		TNativeElementTypes SubElementType( const TInt& aIndex, const TInt& aExpectedCount = -1);
       
   211 		
       
   212 		//Management functions
       
   213 		HBufC8 * DescriptionL();
       
   214 		TInt GetChildListLengthL();
       
   215 		void GetChildListL( TDes8& aChilds);
       
   216 		TInt GetElementsListLengthL( TElementType aType );
       
   217 		void GetElementsListL( TElementType aType, TDes8& aChilds);
       
   218 		TInt RemoveChild( const TUint32& aChildId);
       
   219 		void CheckAllElementsL();
       
   220 		RElementContainer* Container();
       
   221 		void FindAttributesL( TNativeElementTypes aAttributeType, RElementArray& aValuesList);
       
   222 		void CreateExternalId();
       
   223 		TInt GetChildElementCountL();
       
   224 	
       
   225 		//Storage functions
       
   226 		TInt SaveElementL( TBool aRecursive);
       
   227 		void DeleteElementL();
       
   228 		void DeleteMarkRecursiveL();
       
   229 		void ReleaseElement();
       
   230 		void ReserveElement();
       
   231 
       
   232 		//Execution functions
       
   233 		virtual TMatchResponse MatchL( CPolicyProcessor* aPolicyProcessor);
       
   234 		virtual CAttributeValue * ApplyValueL( CPolicyProcessor* aPolicyProcessor);
       
   235 //		void AbsoluteTargetL( TUnionTarget *aTarget);
       
   236 
       
   237 
       
   238 		void AddToElementListL( CElementBase * aElement, TBool aDeleteWithElement);
       
   239 	protected:
       
   240 		HBufC8 * DecodeElementOrIdL( const TLanguageSelector &aLanguage, CElementBase * aElement, const TDecodeMode &aMode);		
       
   241 		void CheckContentL( const TDesC8& aName);
       
   242 		void AddIdElementL( CElementBase * aElement);
       
   243 		
       
   244 	
       
   245 	private:	
       
   246 		//Parsing functions
       
   247 		void AddAttributeL( CPolicyParser *aParser, const TDesC8& aName, const TDesC8& aValue);
       
   248 		void AddContentL( CPolicyParser *aParser, const TDesC8& aName);
       
   249 		void AddElementL( CPolicyParser *aParser, CElementBase * aElement);
       
   250 		virtual TBool ValidElement();
       
   251 		
       
   252 		
       
   253 	protected:
       
   254 		TElementState iElementState;
       
   255 		TSaveType iSaveType; 
       
   256 		TNativeElementTypes iElementType;
       
   257 		TBool iCreateExternalId;
       
   258 		TPtrC8 iElementName;
       
   259 		HBufC8 * iExternalId;
       
   260 	private: 	//Variables
       
   261 		RElementContainer iElements;
       
   262 		TUint32 iParentId;
       
   263 		TUint32 iElementId;
       
   264 		TInt16 iReferenceCount;
       
   265 		
       
   266 		friend class CPolicyParser;
       
   267 		friend class CPolicyStorage;
       
   268 		friend class CElementBase;
       
   269 		friend class CPolicyManager;
       
   270 		friend class CCertificateMaps;
       
   271 		friend class TUnionTarget;
       
   272 		
       
   273 };
       
   274 
       
   275 
       
   276 #endif
       
   277 
       
   278