sl@0: /* sl@0: * Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: #include "T_EntryData.h" sl@0: #include "T_SfSrvServer.h" sl@0: #include "FileserverUtil.h" sl@0: sl@0: // Commands sl@0: _LIT( KCmdAssignmentOperator, "=" ); sl@0: _LIT( KCmdIndexOperator, "[]" ); sl@0: _LIT( KCmdDelete, "~" ); sl@0: _LIT( KCmdIsArchive, "IsArchive" ); sl@0: _LIT( KCmdIsDir, "IsDir" ); sl@0: _LIT( KCmdIsHidden, "IsHidden" ); sl@0: _LIT( KCmdIsReadOnly, "IsReadOnly" ); sl@0: _LIT( KCmdIsSystem, "IsSystem" ); sl@0: _LIT( KCmdIsTypeValid, "IsTypeValid" ); sl@0: _LIT( KCmdIsUidPresent, "IsUidPresent" ); sl@0: _LIT( KCmdMostDerivedUid, "MostDerivedUid" ); sl@0: _LIT( KCmdNew, "new" ); sl@0: _LIT( KCmdSetAttribute, "SetAttribute" ); sl@0: sl@0: // Parameters sl@0: _LIT( KParamAttribute, "attribute" ); sl@0: _LIT( KParamObject, "object" ); sl@0: _LIT( KExpected, "expected" ); sl@0: _LIT( KParamIndex, "index" ); sl@0: _LIT( KParamState, "state" ); sl@0: _LIT( KValue, "value" ); sl@0: sl@0: // Attributes sl@0: _LIT(KEntryAttNormalStr, "KEntryAttNormal"); sl@0: _LIT(KEntryAttReadOnlyStr, "KEntryAttReadOnly"); sl@0: _LIT(KEntryAttHiddenStr, "KEntryAttHidden"); sl@0: _LIT(KEntryAttSystemStr, "KEntryAttSystem"); sl@0: _LIT(KEntryAttVolumeStr, "KEntryAttVolume"); sl@0: _LIT(KEntryAttDirStr, "KEntryAttDir"); sl@0: _LIT(KEntryAttArchiveStr, "KEntryAttArchive"); sl@0: _LIT(KEntryAttXIPStr, "KEntryAttXIP"); sl@0: sl@0: sl@0: // other string values sl@0: #define KTimeFormatSize 30 sl@0: sl@0: sl@0: CT_EntryData* CT_EntryData::NewL( ) sl@0: /** sl@0: * Two phase constructor sl@0: */ sl@0: { sl@0: CT_EntryData* ret = new (ELeave) CT_EntryData( ); sl@0: CleanupStack::PushL( ret ); sl@0: ret->ConstructL(); sl@0: CleanupStack::Pop( ret ); sl@0: return ret; sl@0: } sl@0: sl@0: CT_EntryData::CT_EntryData( ) sl@0: : iEntry(NULL) sl@0: , iFs(NULL) sl@0: sl@0: /** sl@0: * Protected constructor. First phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: void CT_EntryData::ConstructL() sl@0: /** sl@0: * Protected constructor. Second phase construction sl@0: */ sl@0: { sl@0: } sl@0: sl@0: CT_EntryData::~CT_EntryData() sl@0: /** sl@0: * Destructor. sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: sl@0: void CT_EntryData::DoCleanup() sl@0: /** Deltes TEntry class instance */ sl@0: { sl@0: INFO_PRINTF1( _L( "Delete TEntry class instance" ) ); sl@0: delete iEntry; sl@0: iEntry = NULL; sl@0: } sl@0: sl@0: TAny* CT_EntryData::GetObject() sl@0: /** sl@0: * Return a pointer to the object that the data wraps sl@0: * sl@0: * @return pointer to the object that the data wraps sl@0: */ sl@0: { sl@0: return iEntry; sl@0: } sl@0: sl@0: void CT_EntryData::SetObjectL( TAny* aAny ) sl@0: /** sl@0: * Set the wrapped data object with new value sl@0: */ sl@0: { sl@0: DoCleanup(); sl@0: iEntry = static_cast ( aAny ); sl@0: } sl@0: sl@0: void CT_EntryData::DisownObjectL() sl@0: /** sl@0: * Clear the wrapped data object pointer w/o de-initialization sl@0: */ sl@0: { sl@0: iEntry = NULL; sl@0: } sl@0: sl@0: inline TCleanupOperation CT_EntryData::CleanupOperation() sl@0: /** sl@0: * Return static cleanup function sl@0: */ sl@0: { sl@0: return CleanupOperation; sl@0: } sl@0: sl@0: void CT_EntryData::CleanupOperation( TAny* aAny ) sl@0: /** sl@0: * Static cleanup function sl@0: */ sl@0: { sl@0: TEntry* entry = static_cast ( aAny ); sl@0: delete entry; sl@0: } sl@0: sl@0: TBool CT_EntryData::DoCommandL( const TTEFFunction& aCommand, const TTEFSectionName& aSection, const TInt /*aAsyncErrorIndex*/) sl@0: /** sl@0: * Process a command read from the ini file sl@0: * sl@0: * @param aCommand the command to process sl@0: * @param aSection the entry in the ini file requiring the command to be processed sl@0: * sl@0: * @return ETrue if the command is processed sl@0: */ sl@0: { sl@0: TBool retVal = ETrue; sl@0: sl@0: if ( aCommand == KCmdAssignmentOperator ) sl@0: { sl@0: DoCmdAssignmentOperatorL( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIndexOperator ) sl@0: { sl@0: DoCmdIndexOperator( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdDelete ) sl@0: { sl@0: DoCleanup(); sl@0: } sl@0: else if ( aCommand == KCmdIsArchive ) sl@0: { sl@0: DoCmdIsArchive( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsDir ) sl@0: { sl@0: DoCmdIsDir( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsHidden ) sl@0: { sl@0: DoCmdIsHidden( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsReadOnly ) sl@0: { sl@0: DoCmdIsReadOnly( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsSystem ) sl@0: { sl@0: DoCmdIsSystem( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsTypeValid ) sl@0: { sl@0: DoCmdIsTypeValid( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdIsUidPresent ) sl@0: { sl@0: DoCmdIsUidPresent( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdMostDerivedUid ) sl@0: { sl@0: DoCmdMostDerived( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdNew ) sl@0: { sl@0: DoCmdNew( aSection ); sl@0: } sl@0: else if ( aCommand == KCmdSetAttribute ) sl@0: { sl@0: DoCmdSetAttribute( aSection ); sl@0: } sl@0: else sl@0: { sl@0: retVal = EFalse; sl@0: } sl@0: sl@0: return retVal; sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdNew( const TDesC& aSection ) sl@0: /** Creates new TEntry class instance */ sl@0: { sl@0: DoCleanup(); sl@0: sl@0: TPtrC entryObjectName; sl@0: if( GET_OPTIONAL_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) ) sl@0: { sl@0: INFO_PRINTF1( _L( "Create new TEntry(TEntry) class instance." ) ); sl@0: sl@0: TEntry* entryObject = NULL; sl@0: TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName)); sl@0: if ( err == KErrNone ) sl@0: { sl@0: TRAPD( err, iEntry = new (ELeave) TEntry(*entryObject) ); sl@0: if ( err != KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "new TEntry(TEntry) error %d" ), err ); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3( _L( "Unrecognized object name parameter value: %S. Error %d"), &entryObjectName, err ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: else sl@0: { sl@0: INFO_PRINTF1( _L( "Create new TEntry() class instance." ) ); sl@0: TRAPD( err, iEntry = new (ELeave) TEntry() ); sl@0: if ( err!=KErrNone ) sl@0: { sl@0: ERR_PRINTF2( _L( "new TEntry() error %d" ), err ); sl@0: SetError( err ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIndexOperator( const TDesC& aSection ) sl@0: /** Checks if the given UID is the same as required */ sl@0: { sl@0: TInt iniIndex; sl@0: if ( GET_MANDATORY_INT_PARAMETER( KParamIndex, aSection, iniIndex ) ) sl@0: { sl@0: TInt value = (*iEntry)[iniIndex].iUid; sl@0: INFO_PRINTF3( _L( "UID[%d] = %d" ), iniIndex, value ); sl@0: sl@0: TInt iniExpected; sl@0: if ( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, iniExpected ) ) sl@0: { sl@0: if ( value != iniExpected ) sl@0: { sl@0: INFO_PRINTF3( _L( "values not the same %d != %d" ), value, iniExpected ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdAssignmentOperatorL( const TDesC& aSection ) sl@0: /** Assigns another TEntry to this TEntry using "=" operator */ sl@0: { sl@0: TPtrC entryObjectName; sl@0: if( GET_MANDATORY_STRING_PARAMETER( KParamObject, aSection, entryObjectName ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "Assign a %S to this TEntry" ), &entryObjectName ); sl@0: sl@0: TEntry* entryObject = NULL; sl@0: TRAPD( err, entryObject = (TEntry*)GetDataObjectL(entryObjectName)); sl@0: if ( err == KErrNone && entryObject) sl@0: { sl@0: *iEntry = iEntry->operator=(*entryObject); sl@0: } sl@0: else sl@0: { sl@0: ERR_PRINTF3( _L( "Object not found or not initialised: %S. Error %d"), &entryObjectName, err ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: sl@0: if ( !FileserverUtil::VerifyTEntryDataFromIniL(*this, aSection, *iEntry)) sl@0: { sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsArchive( const TDesC& aSection ) sl@0: /** Checks if TEntry has Archive attribute using IsArchive() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsArchive()" ) ); sl@0: TBool result = iEntry->IsArchive(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsDir( const TDesC& aSection ) sl@0: /** Checks if TEntry has Dir attribute using IsDir() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsDir()" ) ); sl@0: TBool result = iEntry->IsDir(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsHidden( const TDesC& aSection ) sl@0: /** Checks if TEntry has Hidden attribute using IsHidden() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsHidden()" ) ); sl@0: TBool result = iEntry->IsHidden(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsReadOnly( const TDesC& aSection ) sl@0: /** Checks if TEntry has ReadOnly attribute using IsReadOnly() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsReadOnly()" ) ); sl@0: TBool result = iEntry->IsReadOnly(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsSystem( const TDesC& aSection ) sl@0: /** Checks if TEntry has System attribute using IsSystem() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsSystem()" ) ); sl@0: TBool result = iEntry->IsSystem(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsTypeValid( const TDesC& aSection ) sl@0: /** Checks if TEntry has a valid UID using IsTypeValid() function */ sl@0: { sl@0: INFO_PRINTF1( _L( "IsTypeValid()" ) ); sl@0: TBool result = iEntry->IsTypeValid(); sl@0: sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdIsUidPresent( const TDesC& aSection ) sl@0: /** Checks if TEntry has a valid UID using IsTypeValid() function */ sl@0: { sl@0: TInt theIntUid; sl@0: TBool expected; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KExpected, aSection, expected ) && sl@0: GET_MANDATORY_INT_PARAMETER( KValue, aSection, theIntUid ) ) sl@0: { sl@0: INFO_PRINTF2( _L( "IsUidPresent( Uid(%d) )" ), theIntUid ); sl@0: TUid theUid; sl@0: theUid.iUid = theIntUid; sl@0: sl@0: TBool result = iEntry->IsUidPresent( theUid ); sl@0: sl@0: if ( !( CompareBool(result, expected) ) ) sl@0: { sl@0: ERR_PRINTF1( _L( "Error compare function result and expected value" )); sl@0: SetBlockResult(EFail); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdMostDerived( const TDesC& aSection ) sl@0: /** checks if UID with given index is the same as the most derived one by using MostDerived() function */ sl@0: { sl@0: TInt id = iEntry->MostDerivedUid().iUid; sl@0: INFO_PRINTF2( _L( "MostDerivedUid = %d" ), id); sl@0: sl@0: TInt expected; sl@0: if( GET_OPTIONAL_INT_PARAMETER( KExpected, aSection, expected ) ) sl@0: { sl@0: if ( expected != id ) sl@0: { sl@0: ERR_PRINTF3( _L( "Error compare UID %d != expected %d" ), id, expected ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: } sl@0: } sl@0: sl@0: void CT_EntryData::DoCmdSetAttribute( const TDesC& aSection ) sl@0: /** Sets or resets attributes */ sl@0: { sl@0: TPtrC attrName; sl@0: TBool attrState; sl@0: if( GET_MANDATORY_BOOL_PARAMETER( KParamState, aSection, attrState ) && sl@0: GET_MANDATORY_STRING_PARAMETER( KParamAttribute, aSection, attrName ) ) sl@0: { sl@0: TBool errHappened = EFalse; sl@0: TUint attr; sl@0: if (attrName == KEntryAttNormalStr) sl@0: { sl@0: attr = KEntryAttNormal; sl@0: } sl@0: else if (attrName == KEntryAttReadOnlyStr) sl@0: { sl@0: attr = KEntryAttReadOnly; sl@0: } sl@0: else if (attrName == KEntryAttHiddenStr) sl@0: { sl@0: attr = KEntryAttHidden; sl@0: } sl@0: else if (attrName == KEntryAttSystemStr) sl@0: { sl@0: attr = KEntryAttSystem; sl@0: } sl@0: else if (attrName == KEntryAttVolumeStr) sl@0: { sl@0: attr = KEntryAttVolume; sl@0: } sl@0: else if (attrName == KEntryAttDirStr) sl@0: { sl@0: attr = KEntryAttDir; sl@0: } sl@0: else if (attrName == KEntryAttArchiveStr) sl@0: { sl@0: attr = KEntryAttArchive; sl@0: } sl@0: else if (attrName == KEntryAttXIPStr) sl@0: { sl@0: attr = KEntryAttXIP; sl@0: } sl@0: else sl@0: { sl@0: errHappened = ETrue; sl@0: } sl@0: sl@0: if ( errHappened ) sl@0: { sl@0: ERR_PRINTF2( _L( "Unknown attribute name parameter: %S" ), &attrName ); sl@0: SetBlockResult( EFail ); sl@0: } sl@0: else sl@0: { sl@0: TPtrC attrStateString; sl@0: GET_MANDATORY_STRING_PARAMETER( KParamState, aSection, attrStateString ); sl@0: INFO_PRINTF3( _L( "SetAttribute(%S, %S)" ), &attrName, &attrStateString); sl@0: sl@0: if ( attrState ) // set attribute sl@0: { sl@0: iEntry->iAtt = iEntry->iAtt | attr; sl@0: } sl@0: else // reset attribute sl@0: { sl@0: iEntry->iAtt = iEntry->iAtt ^ ( iEntry->iAtt & attr ); sl@0: } sl@0: } sl@0: } sl@0: } sl@0: sl@0: sl@0: TBool CT_EntryData::CompareBool( TBool aResult, TBool aExpected ) sl@0: /** compare 2 TBool values, which can be !=0 and !=1 - some TEntry functions return 2, 3 etc */ sl@0: { sl@0: return ( ( aResult > 0 ) == ( aExpected > 0 ) ); sl@0: } sl@0: