persistentstorage/centralrepository/common/inc/inifile.h
changeset 0 08ec8eefde2f
child 55 44f437012c90
equal deleted inserted replaced
-1:000000000000 0:08ec8eefde2f
       
     1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 // All rights reserved.
       
     3 // This component and the accompanying materials are made available
       
     4 // under the terms of "Eclipse Public License v1.0"
       
     5 // which accompanies this distribution, and is available
       
     6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 #ifndef __CENREP_INIFILE_H__
       
    17 #define __CENREP_INIFILE_H__
       
    18 
       
    19 #include <s32file.h>
       
    20 #include "centralrepository.h"
       
    21 #include "log.h"
       
    22 #include "srvdefs.h"
       
    23 
       
    24 using namespace NCentralRepositoryConstants;
       
    25 using namespace NCentralRepositoryResources;
       
    26 
       
    27 //Forward declarations
       
    28 class RRangePolicyArray;
       
    29 class RDefaultMetaArray;
       
    30 class TServerSetting;
       
    31 class TSettingsAccessPolicy;
       
    32 class CSharedRepository;
       
    33 
       
    34 //Max length of one setting statement
       
    35 const TInt KMaxLengthWithPolicyInfo = KMaxBinaryLength * 2 + 64;
       
    36 
       
    37 ////////////////////////////////////////////////////////////////////////////////////////////////
       
    38 // CIniFileIn class
       
    39 /**
       
    40 @internalTechnology
       
    41 */
       
    42 class CIniFileIn : public CBase
       
    43 	{
       
    44 	enum {KReadPolicy,KWritePolicy};
       
    45 
       
    46 public:
       
    47 	enum TIniFileOpenMode {ERomOnly,EInstallOnly,EAuto};
       
    48 
       
    49 public:
       
    50 	static TInt NewLC(RFs& aFs,CIniFileIn*& aIniFile,const TDesC& aFullFileName);
       
    51 	~CIniFileIn();
       
    52 
       
    53 	TInt ReadSettingL(TServerSetting& aSetting,TSecurityPolicy& aSingleReadPolicy,TSecurityPolicy& aSingleWritePolicy, TBool& aSingleReadPolicyFound, TBool& aSingleWritePolicyFound, TBool& aSingleMetaFound);
       
    54 
       
    55 	TInt ReadPlatSecSectionL(TSecurityPolicy& aDefaultReadPolicy, TBool& aGotDefaultReadPolicy,
       
    56 							TSecurityPolicy& aDefaultWritePolicy, TBool& aGotDefaultWritePolicy,
       
    57 							RRangePolicyArray& aRangePolicies);
       
    58 	TInt ReadRdPolicyL(TSecurityPolicy& aReadPolicy);
       
    59 	TInt ReadWrPolicyL(TSecurityPolicy& aWritePolicy);
       
    60 	TInt ReadOwnerSectionL(TUint32 &aOwnerUID) ;
       
    61 	TInt ReadTimeStampSectionL(TTime &aTimeStamp) ;
       
    62 	TInt ReadDefaultMetaSecSectionL(TUint32& aDefaultMeta,
       
    63 	                                RDefaultMetaArray& aDefaultMetaRanges) ;
       
    64 	TInt SkipPlatSecSectionL();
       
    65 	TInt SkipOwnerSectionL() ;
       
    66 	TInt SkipDefaultMetaSectionL() ;
       
    67 	TInt SkipTimeStampSectionL() ;
       
    68 
       
    69 	TInt FindMainSectionL(void) ;
       
    70 	
       
    71 #ifdef CENTREP_TRACE
       
    72 	HBufC* FullName();
       
    73 #endif
       
    74 private:
       
    75 	TInt ReadHeaderL();
       
    76 	TInt ReadSettingOnlyL(TServerSetting& aSetting, TBool& aSingleMetaFound);
       
    77 	TInt ReadStringL(HBufC8*& aString);
       
    78 	TInt ReadString16To8L(HBufC8*& aString);
       
    79 	TInt ReadBinaryL(HBufC8*& aString);
       
    80 	void SkipComments();
       
    81 	void SkipEqualSign();
       
    82 
       
    83 	TInt ReadNumber(TUint32& aVal);
       
    84 	TInt ReadCapabilityL(TCapability& aCapability);
       
    85 	void CheckForAlwaysPassOrFailL(TBool& aAlwaysPass,TBool& aAlwaysFail);
       
    86 	TInt ReadPolicyL(TSecurityPolicy& aPolicy,TInt aPolicyType);
       
    87 	TInt ReadCapabilitiesL(TSecurityPolicy& aPolicy);
       
    88 	TInt ReadSidAndCapabilitiesL(TSecurityPolicy& aPolicy,const TDesC& aPolicyType,
       
    89 								TSecureId& aSid);
       
    90 	TInt ReadRangePoliciesL(const TSecurityPolicy& aDefaultReadPolicy,const TSecurityPolicy& aDefaultWritePolicy,
       
    91 				RRangePolicyArray& aRangePolicies);
       
    92 	TInt ReadRangeMetaDefaultsL(RDefaultMetaArray& aDefaultMetaRanges);
       
    93 
       
    94 
       
    95 	TInt GetPlatSecSectionLC(HBufC*& aSection);
       
    96 	TInt GetTimeStampSectionLC(HBufC*& aSection);
       
    97 	TInt GetOwnerSectionLC(HBufC*& aSection) ;
       
    98 	TInt GetDefaultMetaSectionLC(HBufC*& aSection) ;
       
    99 	TInt GetSectionLC(const TDesC16& aSectionId, HBufC*& aSection) ;
       
   100 	CIniFileIn(RFs& aFs):iFs(aFs){}
       
   101 private:
       
   102 	HBufC* iBuf;
       
   103 #ifdef CENTREP_TRACE
       
   104 	HBufC* iFullName;
       
   105 #endif
       
   106 	TLex iLex;
       
   107 	TLexMark iMainSectionMark;
       
   108 	RFs iFs;
       
   109 	//
       
   110 	};
       
   111 
       
   112 ////////////////////////////////////////////////////////////////////////////////////////////////
       
   113 //The txt persistence is not needed inside the server but rather for the tool
       
   114 #ifdef CENTREP_CONV_TOOL
       
   115 
       
   116 // CIniFileOut class
       
   117 enum TCapAccessMode
       
   118 	{
       
   119 	ECapReadAccess, 
       
   120 	ECapWriteAccess
       
   121 	};
       
   122 /**
       
   123 @internalTechnology
       
   124 */		
       
   125 class CIniFileOut : public CBase
       
   126 	{
       
   127 public:
       
   128 	static CIniFileOut* NewLC(RFs& aFs,const TDesC& aOutFileName);
       
   129 	~CIniFileOut();
       
   130     void CommitL();
       
   131 
       
   132 	void WriteHeaderL();
       
   133 	void WriteOwnerSectionL(TUid aOwner);
       
   134 	void WriteTimeStampL(const TTime& aTime);
       
   135 	void WriteMetaDataL(TUint32 aDefaultMeta,
       
   136 	                    const RDefaultMetaArray& aDefaultMetaRanges);
       
   137 
       
   138 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS
       
   139 	void WritePlatSecL(const TSettingsAccessPolicy& aDefaultAccessPolicy,
       
   140 					   const RRangePolicyArray& aRangePolicies,TUint32 aCreVersion);
       
   141 #else
       
   142   	void WritePlatSecL(const TSecurityPolicy& aDefaultReadPolicy, 
       
   143   					   const TSecurityPolicy& aDefaultWritePolicy,
       
   144   					   const RRangePolicyArray& aRangePolicies);					   
       
   145 #endif					   
       
   146 
       
   147 	void WriteMainSectionHeaderL();
       
   148 	void WriteSettingL(const TServerSetting& aSetting
       
   149 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS	
       
   150 	,TUint32 aCreVersion
       
   151 #endif
       
   152 	);
       
   153 	void WriteSettingL(const TServerSetting& aSetting,
       
   154 					   const TSettingsAccessPolicy& aAccessPolicy
       
   155 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS					   
       
   156 	,TUint32 aCreVersion
       
   157 #endif
       
   158 	);
       
   159 private:
       
   160 	CIniFileOut(RFs& aFs);
       
   161 	void ConstructL(const TDesC& aOutFileName);
       
   162 	void WriteLineL(const TDesC& aData);
       
   163 	void AppendSecurityPolicyL(const TSecurityPolicy& aPolicy,
       
   164 							   TCapAccessMode aRdWrMode);
       
   165 	void DoSettingL(const TServerSetting& aSetting
       
   166 #ifdef SYMBIAN_CENTREP_SUPPORT_MULTIROFS	
       
   167 	,TUint32 aCreVersion
       
   168 #endif	
       
   169 	);
       
   170 
       
   171 private:
       
   172 	TBool		iCommited;
       
   173 	RFile 		iTransFile;			//Transaction file
       
   174 	RFileBuf	iTransFileBuf;		//Transaction file buffer
       
   175 	TParse		iTransFilePath;		//Transaction file name.
       
   176 	TBuf<KMaxLengthWithPolicyInfo> iBuf;//General purpose buffer, used internally
       
   177 	HBufC* iOutFileName;
       
   178 	RFs 		iFs;
       
   179 	};
       
   180 #endif //CENTREP_CONV_TOOL
       
   181 
       
   182 #endif // __CENREP_INIFILE_H__