homescreenpluginsrv/hspsmanager/src/hspsinstallationhandler.cpp
branchRCL_3
changeset 30 a5a39a295112
child 31 8baec10861af
equal deleted inserted replaced
29:0efa10d348c0 30:a5a39a295112
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Implementaion of HSPS MhspsInstallationService interface defined 
       
    15 *                in hspsThemeManagement.h. For details, see the header file.
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <bautils.h>
       
    21 #include <utf.h>
       
    22 #include <centralrepository.h>
       
    23 
       
    24 #include "hsps_builds_cfg.hrh"
       
    25 #include "hspsthememanagement.h"
       
    26 #include "hspsdefinitionrepository.h"
       
    27 #include "hspsodt.h"
       
    28 #include "hspsdefinitionengineinterface.h"
       
    29 #include "hspsdomdocument.h"
       
    30 #include "hspsresource.h"
       
    31 #include "hspsresult.h"
       
    32 #include "hspsthemeserver.h"
       
    33 #include "hspsinstallationhandler.h"
       
    34 #include "hspssecurityenforcer.h"
       
    35 #include "hspsuimanagererrorcodes.h"
       
    36 #include "hspsdomattribute.h"
       
    37 #include "hspsdomlist.h"
       
    38 #include "hspsdomdepthiterator.h"
       
    39 #include "hspsdomnode.h"
       
    40 #include "hspsconfiguration.h"
       
    41 #include "hspsmanifest.h"
       
    42 #include "hspsserverutil.h"
       
    43 #include "hspsfamilylistener.h"
       
    44 
       
    45 
       
    46 #ifdef HSPS_LOG_ACTIVE
       
    47 #include <hspsodtdump.h>
       
    48 #include <hspslogbus.h>
       
    49 #endif
       
    50 
       
    51 #ifdef _hsps_PERFORMANCE_TEST_
       
    52 #include "hspstimemon.h"
       
    53 #endif
       
    54 
       
    55 _LIT8(KUnknownMimeType, "unknown");    
       
    56 
       
    57 _LIT8(KhspsDefinitionEngine, "hspsdefinitionengine");
       
    58 
       
    59 _LIT(KPathDelim, "\\");
       
    60 _LIT(KPrivateInstall, "\\private\\200159c0\\install\\");
       
    61 _LIT(KHsps, "\\hsps\\" );
       
    62 _LIT(KXuikon, "xuikon" );
       
    63 
       
    64 const TInt KMaxMediaTypeLength = 100;
       
    65 
       
    66 // ========================= LOCAL FUNCTIONS ==================================
       
    67 
       
    68 // ----------------------------------------------------------------------------
       
    69 // CleanupResetAndDestroy()
       
    70 // ----------------------------------------------------------------------------
       
    71 //
       
    72 template<class T>
       
    73 static void CleanupResetAndDestroy( TAny* aObj )
       
    74     {
       
    75     if( aObj )
       
    76         {
       
    77         static_cast<T*>( aObj )->ResetAndDestroy();
       
    78         }
       
    79     }
       
    80 
       
    81 // ----------------------------------------------------------------------------
       
    82 // CleanupResetAndDestroyPushL
       
    83 // ----------------------------------------------------------------------------
       
    84 //
       
    85 template<class T>
       
    86 static void CleanupResetAndDestroyPushL(T& aArray)
       
    87     {
       
    88     CleanupStack::PushL( TCleanupItem( &CleanupResetAndDestroy<T>, &aArray ) );
       
    89     }
       
    90 
       
    91 // ========================= MEMBER FUNCTIONS ==================================
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // Callback function for removing repository lock if error occurs while repository is locked
       
    95 // -----------------------------------------------------------------------------
       
    96 //
       
    97 LOCAL_C void UnlockRepository( TAny* aObject )
       
    98     {
       
    99     ChspsDefinitionRepository* DefRep = reinterpret_cast<ChspsDefinitionRepository*>( aObject );
       
   100         
       
   101     if (DefRep->Locked())
       
   102         {
       
   103         DefRep->Unlock();
       
   104         }
       
   105     }
       
   106 
       
   107 // -----------------------------------------------------------------------------
       
   108 // ChspsInstallationHandler::ChspsInstallationHandler()
       
   109 // C++ default constructor can NOT contain any code, that
       
   110 // might leave.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 ChspsInstallationHandler::ChspsInstallationHandler( ChspsThemeServer& aThemeServer )
       
   114     : iThemeServer( aThemeServer ), 
       
   115     iDefinitionRepository( aThemeServer.DefinitionRepository() ),
       
   116     iSecurityEnforcer( aThemeServer.SecurityEnforcer() ),    
       
   117     iCentralRepository( aThemeServer.CentralRepository() ),
       
   118     iHeaderListCache( aThemeServer.HeaderListCache() )
       
   119     {     
       
   120     iPackageVerSupported = EFalse;
       
   121     iInstallationPhase = EhspsPhaseIdle;
       
   122     iConfigurationType = EhspsAppConfiguration;
       
   123     iThemeStatus = EhspsThemeStatusNone;
       
   124     iFileNotFound = EFalse;
       
   125     iLocalized = EFalse;             
       
   126     iDefaultSpecificationSet = EFalse;
       
   127     iDefaultSpecification = ELangNone;
       
   128     iInstallationMode = EServiceHandler;
       
   129     iTrustedInstallation = EFalse;
       
   130 	iInstallationType = EInstallationTypeNew;
       
   131 	iInstallFromUDAEmmc = ETrue;
       
   132 	iFamilyMask = 0;
       
   133     }
       
   134     
       
   135 // -----------------------------------------------------------------------------
       
   136 // ChspsInstallationHandler::NewL
       
   137 // Two-phased constructor.
       
   138 // -----------------------------------------------------------------------------
       
   139 //
       
   140 ChspsInstallationHandler* ChspsInstallationHandler::NewL( ChspsThemeServer& aThemeServer )
       
   141     {
       
   142     ChspsInstallationHandler* h = ChspsInstallationHandler::NewLC( aThemeServer );
       
   143     CleanupStack::Pop( h );
       
   144     return ( h );
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // ChspsInstallationHandler::NewL
       
   149 // Two-phased constructor.
       
   150 // -----------------------------------------------------------------------------
       
   151 //
       
   152 ChspsInstallationHandler* ChspsInstallationHandler::NewLC( ChspsThemeServer& aThemeServer )
       
   153     {
       
   154     ChspsInstallationHandler* h = new (ELeave) ChspsInstallationHandler( aThemeServer );
       
   155     CleanupStack::PushL( h );
       
   156     h->ConstructL();
       
   157     return ( h );
       
   158     }
       
   159 
       
   160 
       
   161 // -----------------------------------------------------------------------------
       
   162 // Destructor
       
   163 // -----------------------------------------------------------------------------
       
   164 //
       
   165 ChspsInstallationHandler::~ChspsInstallationHandler()
       
   166     {
       
   167     delete iXmlParser;
       
   168     delete iOdt;
       
   169     delete iDtdFile;
       
   170     delete iHeaderData;
       
   171     delete iThemeFullName;
       
   172     delete iThemeShortName;
       
   173     delete iThemeVersion;
       
   174     delete iThemeDesc;
       
   175     delete iResourceTag;
       
   176     delete iPackageVersion;
       
   177     if ( iTempLocalizedResourceList )
       
   178         {
       
   179         iTempLocalizedResourceList->ResetAndDestroy();
       
   180         delete iTempLocalizedResourceList;
       
   181         }
       
   182     if( iResourceList )
       
   183         {
       
   184         iResourceList->Reset(); // ODT has an ownership of the items
       
   185         delete iResourceList;
       
   186         }
       
   187     delete iContent;
       
   188     delete iXmlFile;
       
   189     delete iMediaType;
       
   190     delete iResource;
       
   191     delete iResult;
       
   192     
       
   193     if ( iDefEngine )
       
   194         {
       
   195         delete iDefEngine;
       
   196         }
       
   197 
       
   198     iFsSession.Close();
       
   199     REComSession::FinalClose();
       
   200     }
       
   201     
       
   202     
       
   203     
       
   204     
       
   205 // -----------------------------------------------------------------------------
       
   206 // ChspsInstallationHandler::ConstructL
       
   207 // Symbian 2nd phase constructor can leave.
       
   208 // -----------------------------------------------------------------------------
       
   209 //
       
   210 void ChspsInstallationHandler::ConstructL()
       
   211     {
       
   212     User::LeaveIfError( iFsSession.Connect() );
       
   213 
       
   214     _LIT8(KMimeType, "text/xml");
       
   215     MContentHandler* contentHandler = this;
       
   216     iXmlParser = Xml::CParser::NewL( KMimeType, *contentHandler );
       
   217     
       
   218      iDefEngine = ChspsDefinitionEngineInterface::NewL(KhspsDefinitionEngine);
       
   219          
       
   220     iOdt = ChspsODT::NewL();
       
   221     iResourceList = new( ELeave ) CArrayPtrSeg<ChspsResource>( KPathListGranularity ); 
       
   222     iTempLocalizedResourceList = new( ELeave ) CArrayPtrSeg<ChspsResource>( KPathListGranularity );
       
   223     
       
   224     iResult = ChspsResult::NewL();
       
   225     iXmlFile = KNullDesC().AllocL();
       
   226     
       
   227     iMultiInstanceFound = EFalse;    
       
   228     }
       
   229 
       
   230 // -----------------------------------------------------------------------------
       
   231 // ChspsInstallationHandler::ServiceInstallThemeL
       
   232 // Starts the actual installation in ChspsInstallationHandler.
       
   233 // (other items were commented in a header).
       
   234 // -----------------------------------------------------------------------------
       
   235 //
       
   236 void ChspsInstallationHandler::ServiceInstallThemeL( const RMessage2& aMessage )
       
   237     {    
       
   238  	// incoming arguments: TIpcArgs: &iResultData, &aManifestFileName, &aHeader
       
   239  	iMessagePtr = aMessage;
       
   240  	TBuf8<KMaxHeaderDataLength8> headerdata;
       
   241 	
       
   242 	iInstallationPhase = EhspsPhaseIdle;
       
   243 	ThspsServiceCompletedMessage ret = EhspsInstallThemeFailed;
       
   244  	    
       
   245     if ( !iDefinitionRepository.Locked() )
       
   246         {
       
   247         // read name of the manifest file
       
   248         TBuf<KMaxHeaderDataLength8> manifestfilename;                
       
   249         iMessagePtr.ReadL( 1, manifestfilename, 0 );
       
   250 
       
   251 #ifdef HSPS_LOG_ACTIVE  
       
   252         if( iLogBus )
       
   253             {
       
   254             iLogBus->LogText( _L( "ChspsInstallationHandler::ServiceInstallThemeL() - Manifest file '%S'" ),
       
   255                     &manifestfilename );
       
   256             }
       
   257 #endif        
       
   258 
       
   259 		// install the manifest file
       
   260 		ret = hspsInstallTheme( manifestfilename, headerdata );
       
   261 		
       
   262 		// now there will be the time for query validity check
       
   263 		if ( ret == EhspsInstallThemeSuccess )
       
   264 			{
       
   265    		    ret = EhspsInstallPhaseSuccess;
       
   266             }
       
   267         }
       
   268        else
       
   269         {
       
   270         iResult->ResetData();
       
   271         iResult->iSystemError = KErrInUse;
       
   272         } 
       
   273     
       
   274     CompleteRequestL(ret, headerdata);
       
   275     }
       
   276 
       
   277 
       
   278 // -----------------------------------------------------------------------------
       
   279 // ChspsInstallationHandler::ServiceInstallNextPhaseL
       
   280 // Starts subsequent installation phases.
       
   281 // (other items were commented in a header).
       
   282 // -----------------------------------------------------------------------------
       
   283 //
       
   284 void ChspsInstallationHandler::ServiceInstallNextPhaseL( const RMessage2& aMessage )
       
   285     {        
       
   286 #ifdef HSPS_LOG_ACTIVE  
       
   287     if( iLogBus )
       
   288         {
       
   289         iLogBus->LogText( _L( "ChspsInstallationHandler::ServiceInstallNextPhaseL():" ) );
       
   290         }
       
   291 #endif
       
   292     
       
   293     TBuf8<KMaxHeaderDataLength8> headerdata;
       
   294     iResult->ResetData();
       
   295     iInstallationMode = EServiceHandler;
       
   296     ThspsServiceCompletedMessage ret = EhspsInstallThemeFailed;
       
   297     // incoming arguments: TIpcArgs: &iResultData, &KNullDesC, &aHeaderData    
       
   298     iMessagePtr = aMessage;
       
   299     
       
   300     // calling installation of next phase
       
   301     ret = hspsInstallNextPhaseL( headerdata );
       
   302     CompleteRequestL( ret, headerdata );        
       
   303     }
       
   304 
       
   305 
       
   306 // -----------------------------------------------------------------------------
       
   307 // ChspsInstallationHandler::InstallNextPhase()
       
   308 // Must be completed by EhspsInstallThemeSuccess, EhspsInstallPhaseSuccess or EhspsInstallThemeFailed 
       
   309 // (other items were commented in a header).
       
   310 // -----------------------------------------------------------------------------
       
   311 //
       
   312 void ChspsInstallationHandler::hspsInstallNextPhaseL( 
       
   313         TDes8& aHeaderData, 
       
   314         TRequestStatus& aRequestStatus )
       
   315     {
       
   316     ThspsServiceCompletedMessage ret = EhspsServiceNotSupported;
       
   317     iInstallationMode = EAsynchronousObject;
       
   318     iRequestStatus = &aRequestStatus;
       
   319     *iRequestStatus = KRequestPending;
       
   320     ret = hspsInstallNextPhaseL( aHeaderData );
       
   321     CompleteRequestL( ret );
       
   322     }
       
   323 
       
   324 // -----------------------------------------------------------------------------
       
   325 // ChspsInstallationHandler::ResetL()
       
   326 // -----------------------------------------------------------------------------
       
   327 void ChspsInstallationHandler::ResetL()
       
   328     {
       
   329     iThemeFilePath.FillZ();    
       
   330     iFamilyMask = 0;
       
   331     iInstallationPhase = EhspsPhaseInitialise;    
       
   332     iThemeStatus = EhspsThemeStatusNone;
       
   333     iTrustedInstallation = EFalse;
       
   334     iFileNotFound = EFalse;
       
   335     delete iMediaType;
       
   336     iMediaType = NULL;
       
   337     delete iThemeDesc;
       
   338     iThemeDesc = NULL;
       
   339     delete iResourceTag;
       
   340     iResourceTag = NULL;
       
   341     iLocalized = EFalse;    
       
   342     iDefaultSpecificationSet = EFalse;
       
   343     iDefaultSpecification = ELangNone;
       
   344     if ( iOdt )
       
   345        {
       
   346        delete iOdt;
       
   347        iOdt = NULL;
       
   348        iOdt = ChspsODT::NewL();
       
   349        }
       
   350     
       
   351     delete iDtdFile;
       
   352     iDtdFile = NULL;
       
   353     
       
   354     delete iHeaderData;
       
   355     iHeaderData = NULL;
       
   356     if ( iDefEngine )
       
   357        {
       
   358        delete iDefEngine; 
       
   359        iDefEngine = NULL;
       
   360        iDefEngine = ChspsDefinitionEngineInterface::NewL(KhspsDefinitionEngine);
       
   361        }   
       
   362     if ( iResourceList )
       
   363        {
       
   364        iResourceList->Reset(); // ODT has an ownership of the items
       
   365        delete iResourceList;
       
   366        iResourceList = NULL;
       
   367        iResourceList = new( ELeave ) CArrayPtrSeg<ChspsResource>( KPathListGranularity ); 
       
   368        }    
       
   369     if ( iTempLocalizedResourceList )
       
   370        {
       
   371        iTempLocalizedResourceList->ResetAndDestroy(); 
       
   372        delete iTempLocalizedResourceList;
       
   373        iTempLocalizedResourceList = NULL;
       
   374        iTempLocalizedResourceList = new( ELeave ) CArrayPtrSeg<ChspsResource>( KPathListGranularity );
       
   375        }
       
   376     iInstallationType = EInstallationTypeNew;
       
   377     }
       
   378 
       
   379 // -----------------------------------------------------------------------------
       
   380 // ChspsInstallationHandler::hspsInstallTheme()
       
   381 // From MhspsInstallationService 
       
   382 // Must be completed by EhspsInstallThemeSuccess, EhspsInstallPhaseSuccess or EhspsInstallThemeFailed 
       
   383 // (other items were commented in a header).
       
   384 // -----------------------------------------------------------------------------
       
   385 //
       
   386 ThspsServiceCompletedMessage ChspsInstallationHandler::hspsInstallTheme(
       
   387         const TDesC& aManifestFileName, 
       
   388         TDes8& aHeaderData)
       
   389     {
       
   390     // Assume that the installation fails
       
   391     ThspsServiceCompletedMessage ret = EhspsInstallThemeFailed;                       
       
   392     iResult->iXuikonError = 0;    
       
   393     iResult->iIntValue2 = 0;
       
   394     
       
   395     TRAPD( err, DoInstallThemeL(aManifestFileName) );
       
   396     if( !err )
       
   397         {
       
   398         // correct headerdata is in iHeaderData set by CheckHeaderL()
       
   399         aHeaderData = iHeaderData->Des();        
       
   400                    
       
   401         // Set next phase
       
   402         iInstallationPhase = EhspsPhaseCleanup;
       
   403         ret = EhspsInstallThemeSuccess;
       
   404         }
       
   405     else
       
   406         {     
       
   407 #ifdef HSPS_LOG_ACTIVE  
       
   408         if( iLogBus )
       
   409             {
       
   410             iLogBus->LogText( _L( "ChspsInstallationHandler::hspsInstallTheme(): - Installation failed with error code %d" ),
       
   411                     err );
       
   412             }
       
   413 #endif       
       
   414         }
       
   415         
       
   416     iResult->iSystemError = err;
       
   417     return ret;
       
   418     }
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // ChspsInstallationHandler::DoInstallThemeL()
       
   422 // -----------------------------------------------------------------------------
       
   423 void ChspsInstallationHandler::DoInstallThemeL(
       
   424         const TDesC& aManifest )
       
   425     {        
       
   426     // Reset memeber variables    
       
   427     ResetL();
       
   428         
       
   429     TParsePtrC parsePtr( aManifest );        
       
   430                 
       
   431     // Store the path to the installation file     
       
   432     __ASSERT_DEBUG( aManifest.Length() < KMaxFileName, User::Leave( KErrBadName ) );
       
   433     iThemeFilePath.Copy( parsePtr.DriveAndPath() );    
       
   434         
       
   435     // If trying to install widgets from one of our private install directories
       
   436     const TPath path = parsePtr.Path();
       
   437     if( path.Length() > KPrivateInstall().Length() 
       
   438             && path.Left( KPrivateInstall().Length() ) == KPrivateInstall() ) 
       
   439         {                    
       
   440         // Check if ROM or UDA installation was requested
       
   441         if( parsePtr.DrivePresent() )
       
   442             {            
       
   443             TInt driveNumber;
       
   444             if ( RFs::CharToDrive( parsePtr.Drive()[0], driveNumber ) == KErrNone )
       
   445                 {
       
   446                 iTrustedInstallation = ( driveNumber == EDriveZ || driveNumber == EDriveC );                
       
   447                 }
       
   448             }
       
   449         }    
       
   450             
       
   451     if( !BaflUtils::FileExists( iFsSession, aManifest ) )
       
   452         {
       
   453 #ifdef HSPS_LOG_ACTIVE    
       
   454         if ( iLogBus )
       
   455             {           
       
   456             iLogBus->LogText( _L( "ChspsInstallationHandler::DoInstallThemeL() - *** Manifest was not found!" ) );
       
   457             }
       
   458 #endif    
       
   459         User::Leave( KErrNotFound );
       
   460         }
       
   461        
       
   462 #ifdef HSPS_LOG_ACTIVE    
       
   463     if ( iLogBus )
       
   464         {            
       
   465         iLogBus->LogText( _L( "ChspsInstallationHandler::DoInstallThemeL() - *** Parsing a manifest file" ) );
       
   466         }
       
   467 #endif       
       
   468     
       
   469     // Parse XML from the manifest file
       
   470     Xml::ParseL( *iXmlParser, iFsSession, aManifest );    
       
   471                     
       
   472     // The manifest file has been read at this point and following callbacks have been executed:
       
   473     // OnContent(), OnStartElement() and OnEndElement()
       
   474     
       
   475     // Performance optimization: do not check if installing from rom.
       
   476     if( !iTrustedInstallation )
       
   477         {
       
   478         // Check type of installation        
       
   479         TBool instancesFound = IsPluginUsedInAppConfsL();            
       
   480         if( iThemeServer.PluginInHeaderCache( TUid::Uid( iThemeUid ) ) && instancesFound )                    
       
   481             {
       
   482             // Plugin should be found from cache, update notifications are
       
   483             // sent only when plugins are used by one/more app configurations
       
   484             iInstallationType = EInstallationTypeUpdate;
       
   485             }
       
   486         else
       
   487             {
       
   488             iInstallationType = EInstallationTypeNew;
       
   489             }
       
   490         }                
       
   491         
       
   492     // Check the parsed input        
       
   493     FinalizeParsingL();                    
       
   494     }
       
   495 
       
   496 // -----------------------------------------------------------------------------
       
   497 // ChspsInstallationHandler::GetInterfacePath() 
       
   498 // -----------------------------------------------------------------------------
       
   499 //
       
   500 TFileName ChspsInstallationHandler::GetInterfacePath()
       
   501     {        
       
   502     TFileName path;
       
   503     
       
   504     TParse pathParser;
       
   505     pathParser.Set( iThemeFilePath, NULL, NULL );                               
       
   506     pathParser.PopDir(); // pop locale specific folder  
       
   507                 
       
   508     TPtrC parentFolder = pathParser.FullName().Mid( pathParser.FullName().Length() - KHsps().Length() );
       
   509     if ( parentFolder.CompareF(KHsps) == 0 )
       
   510         {
       
   511         pathParser.PopDir(); // pop "hsps" folder 
       
   512         path.Copy( pathParser.FullName() );
       
   513         path.Append( KXuikon );
       
   514         path.Append( KPathDelim );
       
   515         }
       
   516     return path;
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // ChspsInstallationHandler::ValidateL() 
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 void ChspsInstallationHandler::FinalizeParsingL()
       
   524     {               
       
   525     // Add resources
       
   526     TFileName interfacePath( GetInterfacePath() );       
       
   527     if ( interfacePath.Length() )        
       
   528         {
       
   529         // If name of the DTD file was specified in the manifest
       
   530         if ( iDtdFile )
       
   531             { 
       
   532             TParse pathParser;
       
   533             pathParser.Set( iThemeFilePath, NULL, NULL );                               
       
   534             pathParser.PopDir(); // pop locale specific folder
       
   535             
       
   536             // Find locale specific DTD file
       
   537             AddLocalesL( pathParser.FullName(), ETrue );
       
   538             }
       
   539         
       
   540         // Find Xuikon resources of each locale 
       
   541         AddInterfaceResourcesV2L( interfacePath );
       
   542        }
       
   543     else
       
   544        {
       
   545        // Find DTD files and locale specific resources from subdirectories under the installation path
       
   546        AddLocalesL( iThemeFilePath, EFalse );                       
       
   547        }       
       
   548           
       
   549    // Validate other input from the manifest
       
   550    CheckHeaderL();
       
   551            
       
   552    if ( iSecurityEnforcer.CheckThemeLockingL( *iOdt ) )
       
   553        {
       
   554        iResult->iXuikonError = KErrThemeStatusLocked;    
       
   555 #ifdef HSPS_LOG_ACTIVE  
       
   556        if( iLogBus )
       
   557            {
       
   558            iLogBus->LogText( _L( "ChspsInstallationHandler::ValidateL(): - CheckThemeLockingL" ) );
       
   559            }
       
   560 #endif              
       
   561        User::Leave( KErrAccessDenied );
       
   562        } 
       
   563                            
       
   564 #ifdef HSPS_LOG_ACTIVE  
       
   565    // printing some debug-info
       
   566    TPtrC xmlfile = iXmlFile->Des();
       
   567    if( iLogBus )
       
   568        {
       
   569        iLogBus->LogText( _L( "ChspsInstallationHandler::ValidateL(): - iXmlFile = '%S'" ),
       
   570                &xmlfile );
       
   571 
       
   572        iLogBus->LogText( _L( "ChspsInstallationHandler::ValidateL(): - resources included = %d" ),
       
   573                iResourceList->Count() );
       
   574        }
       
   575 #endif                   
       
   576     }
       
   577          
       
   578 
       
   579 // -----------------------------------------------------------------------------
       
   580 // Execution of specific installation phases and transitions in between.
       
   581 // Must be completed by EhspsInstallThemeSuccess, EhspsInstallPhaseSuccess or EhspsInstallThemeFailed 
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 ThspsServiceCompletedMessage ChspsInstallationHandler::hspsInstallNextPhaseL( TDes8& aHeaderData )
       
   585        {
       
   586        // Defaults
       
   587        ThspsServiceCompletedMessage ret = EhspsInstallPhaseSuccess;
       
   588        TInt errorCode = KErrNone;   
       
   589     
       
   590     if ( !iDefinitionRepository.Locked() )
       
   591         {
       
   592         iDefinitionRepository.Lock();
       
   593         }
       
   594 
       
   595     //For unlocking repository in error cases
       
   596     CleanupStack::PushL( TCleanupItem( UnlockRepository, &iDefinitionRepository ) );
       
   597     
       
   598        switch ( iInstallationPhase )
       
   599         {
       
   600         case EhspsPhaseIdle:
       
   601                {
       
   602                ret = EhspsServiceRequestError;
       
   603                }
       
   604                break;
       
   605         
       
   606         case EhspsPhaseCleanup:
       
   607             {            
       
   608             if ( iOdt )
       
   609                 {
       
   610                 // Remove existing/old files from the Plug-in Repository
       
   611                 TRAP( errorCode, CleanupL( *iOdt ) );                
       
   612                 }
       
   613             if ( errorCode )
       
   614                 {
       
   615                 iResult->iSystemError = errorCode;
       
   616                 iResult->iXuikonError = errorCode;
       
   617                 CleanupStack::Pop(&iDefinitionRepository);
       
   618                 return EhspsInstallThemeFailed;
       
   619                 } 
       
   620             else
       
   621                 {
       
   622                 iInstallationPhase = EhspsPhaseInstallSkeleton;
       
   623                 }
       
   624             }
       
   625                break;
       
   626                                        
       
   627         case EhspsPhaseInstallSkeleton:
       
   628                {
       
   629                // Parses and stores DOM into the ODT being installed
       
   630             iResult->iIntValue2 = 0;
       
   631                TRAP( errorCode, InstallSkeletonL( ret ) );
       
   632                if ( errorCode )
       
   633                    {
       
   634                    ret = EhspsInstallThemeFailed;
       
   635                    }
       
   636                else
       
   637                    {
       
   638                    iResult->iIntValue2 = 0;
       
   639                    
       
   640                    // Success - installation finished
       
   641                 ret = EhspsInstallThemeSuccess;
       
   642                 iInstallationPhase = EhspsPhaseIdle;
       
   643                    }
       
   644                }
       
   645                break;
       
   646                    
       
   647         default:
       
   648             {
       
   649             iResult->iSystemError = KErrNotReady;
       
   650             ret = EhspsServiceRequestError;
       
   651             }
       
   652             break;
       
   653         } // switch
       
   654         
       
   655        if ( iHeaderData )
       
   656            {
       
   657            aHeaderData = iHeaderData->Des();
       
   658            }
       
   659        else
       
   660            {
       
   661            aHeaderData = KNullDesC8;
       
   662            }
       
   663    
       
   664     CleanupStack::Pop(&iDefinitionRepository);
       
   665        return ret;
       
   666        }
       
   667             
       
   668             
       
   669 // -----------------------------------------------------------------------------
       
   670 // ChspsInstallationHandler::hspsCancelInstallTheme()
       
   671 // Cancels the theme installation
       
   672 // (other items were commented in a header).
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 ThspsServiceCompletedMessage ChspsInstallationHandler::hspsCancelInstallTheme()
       
   676     {
       
   677     TRAP_IGNORE( CompleteRequestL( EhspsServiceRequestCanceled ));
       
   678     return EhspsServiceRequestCanceled;
       
   679     }            
       
   680 
       
   681 
       
   682 // -----------------------------------------------------------------------------
       
   683 // ChspsInstallationHandler::CheckAutoInstallationValidityL()
       
   684 // Returns EFalse if the user tries to install Licensee default theme
       
   685 // (other items were commented in a header).
       
   686 // -----------------------------------------------------------------------------
       
   687 //
       
   688 TBool ChspsInstallationHandler::CheckAutoInstallationValidityL()
       
   689     {
       
   690     if ( iOdt->Flags() & EhspsThemeStatusLicenceeDefault )
       
   691         {
       
   692         iResult->iXuikonError = KErrIllegalInstallation; 
       
   693         return EFalse;
       
   694         }
       
   695     return ETrue;
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // ChspsInstallationHandler::SetLogBus()
       
   700 // -----------------------------------------------------------------------------
       
   701 //
       
   702 #ifdef HSPS_LOG_ACTIVE        
       
   703 void ChspsInstallationHandler::SetLogBus( ChspsLogBus* aLogBus )
       
   704     {
       
   705     iLogBus = aLogBus;
       
   706     }
       
   707 #endif
       
   708 
       
   709 
       
   710 // ChspsInstallationHandler::InstallOdtL()
       
   711 // Installs DOM-document ODT and processes resource list
       
   712 // (other items were commented in a header).
       
   713 // -----------------------------------------------------------------------------
       
   714 //
       
   715 void ChspsInstallationHandler::InstallSkeletonL( ThspsServiceCompletedMessage& /*aReturnMsg*/ )
       
   716     {
       
   717 #ifdef HSPS_LOG_ACTIVE  
       
   718     if( iLogBus )
       
   719         {
       
   720         iLogBus->LogText( _L( "hspsInstallationHandler::InstallSkeletonL(): - installing and localizing configuration" ) );
       
   721         }
       
   722 #endif  
       
   723           
       
   724     iOdt->SetOdtLanguage( ELangNone );
       
   725         
       
   726     // Parse DOM
       
   727     ParseDocumentL( *iOdt );
       
   728     
       
   729     // Save ODT itself as a resource        
       
   730     SetODTAsResourceL( *iOdt );                               
       
   731                                                      
       
   732     // Add resources parsed from the manifest file into the new ODT instance, generate
       
   733     // target paths and update the iResourcesList array with the new paths
       
   734     User::LeaveIfError( iDefinitionRepository.SetResourceListL( *iOdt, *iResourceList ) );      
       
   735            
       
   736     // Update DOM's configuration node with attributes from the manifest    
       
   737     hspsServerUtil::GenerateConfigurationAttributesL( *iOdt );
       
   738     
       
   739     TBuf8<10> uid;
       
   740     _LIT8( KFormat8, "%X" );
       
   741     _LIT8( KHexPrefix, "0x" );
       
   742     uid.Append( KHexPrefix );
       
   743     uid.AppendFormat( KFormat8, iOdt->ThemeUid() );
       
   744 
       
   745     // Update configuration max child count
       
   746     if ( hspsServerUtil::FindNodeByTagL( 
       
   747         KPluginsElement, 
       
   748         *( iOdt->DomDocument().RootNode() ) ) )
       
   749         {
       
   750         TPtrC8 maxChildCnt;
       
   751         // Plugins node found - Configuration can include child configurations
       
   752         TRAPD( err, hspsServerUtil::GetAttributeValueL( 
       
   753             *iOdt,
       
   754             KConfigurationElement,
       
   755             KConfigurationAttrUid,
       
   756             uid,
       
   757             KConfigurationAttrMaxChild,
       
   758             maxChildCnt) );
       
   759         if ( err )
       
   760             {
       
   761             // Set default max child configuration count
       
   762             hspsServerUtil::SetAttributeValueL(
       
   763                 *iOdt,
       
   764                 KConfigurationElement,
       
   765                 KConfigurationAttrUid,
       
   766                 uid,
       
   767                 KConfigurationAttrMaxChild,
       
   768                 _L8( "6" ) );
       
   769             }
       
   770         }
       
   771     else
       
   772         {
       
   773         // Configuration cannot indluce child configurations
       
   774         hspsServerUtil::SetAttributeValueL(
       
   775             *iOdt,
       
   776             KConfigurationElement,
       
   777             KConfigurationAttrUid,
       
   778             uid,
       
   779             KConfigurationAttrMaxChild,
       
   780             _L8( "0" ) );
       
   781         }
       
   782 
       
   783     if ( iTrustedInstallation )
       
   784         {
       
   785         // Update configuration state to KConfStateConfirmed
       
   786         hspsServerUtil::SetAttributeValueL( 
       
   787             *iOdt,
       
   788             KConfigurationElement,
       
   789             KConfigurationAttrUid,
       
   790             uid,
       
   791             KConfigurationAttrState,
       
   792             KConfStateConfirmed
       
   793             );
       
   794         }
       
   795     
       
   796     iOdt->SetOdtLanguage( ELangTest );
       
   797     
       
   798     // Add a resouces node and its objects from the manifest into the DOM
       
   799     hspsServerUtil::GenerateObjectAttributesL( *iOdt );        
       
   800         
       
   801 
       
   802         
       
   803             
       
   804     // Make localizations according to the active device language
       
   805     iThemeServer.LocalizeL(
       
   806         *iDefEngine,
       
   807         *iOdt );
       
   808     
       
   809     // Store the ODT instance into the file system
       
   810     iDefinitionRepository.SetOdtL( *iOdt );  
       
   811        }
       
   812 
       
   813 // -----------------------------------------------------------------------------
       
   814 // ChspsInstallationHandler::CheckHeaderL()
       
   815 // Checks the installed theme's header correctness
       
   816 // (other items were commented in a header).
       
   817 // -----------------------------------------------------------------------------
       
   818 //
       
   819 void ChspsInstallationHandler::CheckHeaderL()
       
   820     {
       
   821     // Check whether the manifest is supported by the installer
       
   822     if ( !iPackageVerSupported )
       
   823         {
       
   824 #ifdef HSPS_LOG_ACTIVE  
       
   825         if( iLogBus )
       
   826             {
       
   827             iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - package version is not supported by the server!" ) );
       
   828             iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - Update plug-in configurations and try again" ) );
       
   829             }
       
   830 #endif
       
   831     
       
   832         User::Leave( KErrNotSupported );     
       
   833         }
       
   834 
       
   835     ChspsFamily* family = iThemeServer.Family();
       
   836     if ( !family )
       
   837         {
       
   838         User::Leave( KErrNotSupported );
       
   839         }
       
   840 
       
   841     ThspsFamily familyType = family->GetFamilyType();
       
   842     if ( familyType == EhspsFamilyUnknown )
       
   843         {
       
   844         User::Leave( KErrNotSupported );
       
   845         }
       
   846 #if !defined(WINSCW) && !defined(__WINS__)
       
   847     if ( !( familyType & iFamilyMask ) )
       
   848         {
       
   849         User::Leave( KErrNotSupported );
       
   850         }
       
   851 #endif // !defined(WINSCW) && !defined(__WINS__)
       
   852     iOdt->SetFamily( iFamilyMask );    
       
   853             
       
   854     // Store root, provider and theme uid
       
   855     if ( iRootUid && iProviderUid && iThemeUid )
       
   856         {
       
   857         iOdt->SetRootUid( iRootUid );
       
   858         iOdt->SetProviderUid( iProviderUid );
       
   859         iOdt->SetThemeUid( iThemeUid );
       
   860         }
       
   861     else
       
   862         {
       
   863 #ifdef HSPS_LOG_ACTIVE  
       
   864         if( iLogBus )
       
   865             {
       
   866             iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - Manifest file error, no UIDs" ) );
       
   867             }
       
   868 #endif    
       
   869         
       
   870         // If the content is empty, the file is supposedly wrong
       
   871         if( !iContent )
       
   872             {
       
   873             iResult->iXuikonError = KErrWrongManifestFile;
       
   874             User::Leave( KErrNotFound );            
       
   875             }
       
   876         // something goes wrong...
       
   877         if( !iRootUid && !iProviderUid && !iThemeUid &&
       
   878             !iThemeFullName && !iThemeShortName && !iThemeVersion )
       
   879             {
       
   880             iResult->iXuikonError = KErrOtherXuikonError;
       
   881             User::Leave( KErrNotFound );
       
   882             }
       
   883         if( !iRootUid )
       
   884             {
       
   885             iResult->iXuikonError = KErrAppUidDefinitionMissing;
       
   886             User::Leave( KErrNotFound );
       
   887             }
       
   888         if( !iProviderUid )
       
   889             {
       
   890             iResult->iXuikonError = KErrProviderUidDefinitionMissing;
       
   891             User::Leave( KErrNotFound );
       
   892             }
       
   893         if( !iThemeUid )
       
   894             {
       
   895             iResult->iXuikonError = KErrThemeUidDefinitionMissing;
       
   896             User::Leave( KErrNotFound );
       
   897             }
       
   898         User::Leave(KErrNotFound);
       
   899         }
       
   900     
       
   901     // Store name, short name and version
       
   902     HBufC* themeFullName = NULL;
       
   903     HBufC* themeShortName = NULL;
       
   904     HBufC* themeVersion = NULL;    
       
   905     if ( iThemeFullName && iThemeShortName && iThemeVersion )
       
   906         {
       
   907         themeFullName = HBufC::NewLC( iThemeFullName->Length() );
       
   908         themeFullName->Des().Copy( *iThemeFullName ); 
       
   909         themeShortName = HBufC::NewLC( iThemeShortName->Length() );
       
   910         themeShortName->Des().Copy( *iThemeShortName ); 
       
   911         themeVersion = HBufC::NewLC( iThemeVersion->Length() );
       
   912         themeVersion->Des().Copy( *iThemeVersion );
       
   913         }
       
   914     else
       
   915         {
       
   916 #ifdef HSPS_LOG_ACTIVE  
       
   917         if( iLogBus )
       
   918             {
       
   919             iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - Manifest file error, no names" ) );
       
   920             }
       
   921 #endif    
       
   922         
       
   923         if( !iThemeFullName )
       
   924             {
       
   925             iResult->iXuikonError = KErrThemeFullNameDefinitionMissing;
       
   926             User::Leave( KErrNotFound );
       
   927             }
       
   928         if( !iThemeShortName )
       
   929             {
       
   930             iResult->iXuikonError = KErrThemeShortDefinitionNameMissing;
       
   931             User::Leave( KErrNotFound );
       
   932             }
       
   933         if( !iThemeVersion )
       
   934             {
       
   935             iResult->iXuikonError = KErrThemeVersionDefinitionMissing;
       
   936             User::Leave( KErrNotFound );
       
   937             }
       
   938         User::Leave(KErrNotFound);
       
   939         }
       
   940     iOdt->SetThemeFullNameL( themeFullName->Des() );
       
   941     iOdt->SetThemeShortNameL( themeShortName->Des() );
       
   942     iOdt->SetThemeVersionL( themeVersion->Des() );
       
   943     if ( iThemeDesc )
       
   944         {        
       
   945         HBufC* buf = HBufC::NewLC( iThemeDesc->Length() );
       
   946         buf->Des().Copy( iThemeDesc->Des() );
       
   947         iOdt->SetDescriptionL( buf->Des() );
       
   948         CleanupStack::PopAndDestroy( buf );
       
   949         }    
       
   950     iOdt->SetMultiInstance( iMultiInstance );
       
   951     iMultiInstanceFound = EFalse;
       
   952 
       
   953     CleanupStack::PopAndDestroy( themeVersion );
       
   954     CleanupStack::PopAndDestroy( themeShortName );
       
   955     CleanupStack::PopAndDestroy( themeFullName );
       
   956     
       
   957     iOdt->SetConfigurationType( iConfigurationType );
       
   958     iOdt->SetFlags( iThemeStatus );   
       
   959     
       
   960     // Check that there is only one restorable application configuration 
       
   961     // for a client in a device family     
       
   962     if( iOdt->Flags() & EhspsThemeStatusLicenceeRestorable
       
   963         && iConfigurationType == EhspsAppConfiguration )
       
   964         {               
       
   965         ChspsODT* searchMask = ChspsODT::NewL();
       
   966         CleanupStack::PushL( searchMask );                
       
   967         searchMask->SetRootUid( iOdt->RootUid() );        
       
   968         searchMask->SetFlags( EhspsThemeStatusLicenceeRestorable );
       
   969         
       
   970         TInt pos( 0 );
       
   971         ChspsODT* header = NULL;
       
   972         iThemeServer.GetConfigurationHeader( *searchMask, header, pos );
       
   973         while( header )
       
   974             {
       
   975             // If another plugin has already been installed with the restorable status 
       
   976             if( header->Family() & iOdt->Family() 
       
   977                     && header->ThemeUid() != iOdt->ThemeUid() )
       
   978                 {
       
   979                 // Unset the restorable bit
       
   980                 TUint flags = iOdt->Flags();                
       
   981                 flags &= ~EhspsThemeStatusLicenceeRestorable;
       
   982                 iOdt->SetFlags( flags );
       
   983 #ifdef HSPS_LOG_ACTIVE  
       
   984                 if( iLogBus )
       
   985                     {
       
   986                     iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - too many restorable plugins were found!" ) );
       
   987                     }
       
   988 #endif                
       
   989                 break;
       
   990                 }
       
   991             
       
   992             // Get next application configuration header
       
   993             pos++;
       
   994             iThemeServer.GetConfigurationHeader( *searchMask, header, pos );
       
   995             }
       
   996         
       
   997         header = NULL;
       
   998         CleanupStack::PopAndDestroy();
       
   999         }
       
  1000     
       
  1001     // If configuration file is missing
       
  1002     if( !iXmlFile ) 
       
  1003         {
       
  1004 #ifdef HSPS_LOG_ACTIVE  
       
  1005         if( iLogBus )
       
  1006             {
       
  1007             iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - XML was not declared!" ) );
       
  1008             }
       
  1009 #endif                   
       
  1010         iResult->iXuikonError = KErrXmlFileDefinitionMissing;
       
  1011         User::Leave( KErrNotFound );
       
  1012         }
       
  1013      
       
  1014     // If name of the DTD file has been set
       
  1015     if ( iDtdFile )
       
  1016         {
       
  1017         // Expect localization for at least ELangTest (folder name "00")
       
  1018         if ( !iDefaultSpecificationSet || iDefaultSpecification != ELangTest )
       
  1019             {
       
  1020             iResult->iXuikonError = KErrDtdFileNotFound;
       
  1021 #ifdef HSPS_LOG_ACTIVE  
       
  1022             if( iLogBus )
       
  1023                 {
       
  1024                 iLogBus->LogText( _L( "ChspsInstallationHandler::CheckHeaderL(): - check localization!" ) );
       
  1025                 }
       
  1026 #endif            
       
  1027             User::Leave( KErrNotFound );
       
  1028             }
       
  1029         }
       
  1030     
       
  1031     // all header-information is in place, now try to marshall it as a return of the service call
       
  1032     iHeaderData = iOdt->MarshalHeaderL();
       
  1033     }
       
  1034 
       
  1035 // -----------------------------------------------------------------------------
       
  1036 // ChspsInstallationHandler::ParseDocumentL
       
  1037 // Parses the skeleton DOM with the help of Definition Engine
       
  1038 // (other items were commented in a header).
       
  1039 // -----------------------------------------------------------------------------
       
  1040 //
       
  1041 void ChspsInstallationHandler::ParseDocumentL( ChspsODT& aOdt )
       
  1042     {
       
  1043     TInt deferror = KErrNone;
       
  1044     TInt errorCode = KErrNone;
       
  1045     ChspsDefinitionEngineInterface::TError t_error;  
       
  1046 
       
  1047 #ifdef _hsps_PERFORMANCE_TEST_    
       
  1048     // service time prints
       
  1049     _LIT( KStartTiming, "ChspsInstallationHandler::ParseDocumentL(): - calling iDefEngine->CreateDOM()..");
       
  1050     TTime start_time = ChspsTimeMon::StartTiming( KStartTiming );
       
  1051 #endif    
       
  1052     
       
  1053     t_error = iDefEngine->CreateDOM( iFsSession, *iXmlFile, aOdt );
       
  1054           
       
  1055     deferror = t_error.iDefEngError + t_error.iSubComponentError;
       
  1056     
       
  1057     if (!deferror)
       
  1058         {
       
  1059         // get ODT information
       
  1060            ChspsDomDocument& domDocument = aOdt.DomDocument();
       
  1061         TInt domNodeCount = domDocument.DomNodeCount();
       
  1062         // write the result
       
  1063         iResult->iIntValue1 = 0;
       
  1064         iResult->iIntValue2 = domNodeCount;
       
  1065 
       
  1066 #ifdef _hsps_PERFORMANCE_TEST_  
       
  1067         // calculating service time
       
  1068          _LIT( KStopTiming, "ChspsInstallationHandler::ParseDocumentL(): - Parsing success." );
       
  1069          ChspsTimeMon::StopTiming(start_time, KStopTiming );
       
  1070 #endif
       
  1071         }
       
  1072     else
       
  1073         {
       
  1074         errorCode = KErrCorrupt;
       
  1075         iResult->iXuikonError = errorCode;
       
  1076 
       
  1077         iResult->iIntValue1 = t_error.iDefEngError;
       
  1078         iResult->iIntValue2 = t_error.iSubComponentError;
       
  1079 
       
  1080 #ifdef HSPS_LOG_ACTIVE  
       
  1081         if( iLogBus )
       
  1082             {
       
  1083             iLogBus->LogText( _L( "ChspsInstallationHandler::ParseDocumentL(): - TRAP returned %d" ),
       
  1084                     errorCode );
       
  1085             iLogBus->LogText( _L( "ChspsInstallationHandler::ParseDocumentL(): - ChspsDefinition Engine::TError.iParserError: %d" ),
       
  1086                     t_error.iDefEngError );
       
  1087             iLogBus->LogText( _L( "ChspsInstallationHandler::ParseDocumentL(): - ChspsDefinition Engine::TError.iSubComponentError: %d" ),
       
  1088                     t_error.iSubComponentError );
       
  1089             }
       
  1090 #endif      
       
  1091         }
       
  1092           
       
  1093     User::LeaveIfError(errorCode);        
       
  1094     }
       
  1095 
       
  1096 // -----------------------------------------------------------------------------
       
  1097 // ChspsInstallationHandler::AddResourceL()
       
  1098 // Adds parsed resource into a temporary resource list, from which the resources
       
  1099 // are applied to an ODT instance at later phase
       
  1100 // -----------------------------------------------------------------------------
       
  1101 //
       
  1102 void ChspsInstallationHandler::AddResourceL(
       
  1103         CArrayPtrSeg<ChspsResource>& aArray, 
       
  1104         const TPtrC aFilename,
       
  1105         const TLanguage aLanguage,
       
  1106         const ThspsResourceType aResourceType,
       
  1107         const TPtrC8 aMimetype,
       
  1108         const TPtrC8 aTag )        
       
  1109     {        
       
  1110     TParsePtrC parsePtr( aFilename );
       
  1111         
       
  1112     ChspsResource* r = ChspsResource::NewL();
       
  1113     CleanupStack::PushL(r);
       
  1114     
       
  1115     r->SetLockingPolicy( EhspsUnlocked );
       
  1116     if ( iThemeStatus & EhspsThemeStatusLicenceeDefault )
       
  1117         {
       
  1118         r->SetLockingPolicy( EhspsLocked );
       
  1119         }                   
       
  1120     r->SetResourceIdL( parsePtr.NameAndExt() );
       
  1121     
       
  1122     // Common resources are parsed first - thus when the iLanguageSpecification is other than ELangNone, 
       
  1123     // then we are parsing language specific resources
       
  1124     r->SetConfigurationUid( iThemeUid );
       
  1125     r->SetLanguage( aLanguage );       
       
  1126     r->SetFileNameL( aFilename );
       
  1127     r->SetResourceType( aResourceType );
       
  1128     if ( aMimetype.Length() )
       
  1129         {                
       
  1130         r->SetMimeTypeL( TDataType( aMimetype ) );
       
  1131         }
       
  1132     const TInt l = aTag.Length();
       
  1133     if ( l )
       
  1134         {
       
  1135         HBufC* buf = HBufC::NewLC( l );
       
  1136         buf->Des().Copy( aTag );
       
  1137         r->SetTagsL( *buf );
       
  1138         CleanupStack::PopAndDestroy( buf );
       
  1139         }
       
  1140     aArray.AppendL( r );
       
  1141     
       
  1142     CleanupStack::Pop( r );
       
  1143     }
       
  1144     
       
  1145 // -----------------------------------------------------------------------------
       
  1146 // ChspsInstallationHandler::CleanupL()
       
  1147 // Executes cleaning of the target folder prior to the installation process
       
  1148 // -----------------------------------------------------------------------------
       
  1149 //    
       
  1150 void ChspsInstallationHandler::CleanupL( const ChspsODT& aOdt )    
       
  1151     {        
       
  1152 #ifdef HSPS_LOG_ACTIVE  
       
  1153     if( iLogBus )
       
  1154         {
       
  1155         iLogBus->LogText( _L( "hspsInstallationHandler::CleanupL(): - removing previous installation" ) );
       
  1156         }
       
  1157 #endif    
       
  1158     
       
  1159     // Get ODT's relative path in Plug-in Repository without the drive information             
       
  1160     HBufC* relativePath = HBufC::NewLC( KMaxFileName );
       
  1161     TPtr ptr = relativePath->Des();             
       
  1162     iDefinitionRepository.GetODTPathL( aOdt, ptr );
       
  1163     
       
  1164     // Strip file name and append path with a drive symbol
       
  1165     TParsePtr parser( ptr );
       
  1166     parser.PopDir();               
       
  1167     TPtrC confPath = parser.Path();                          
       
  1168     TPath file;                        
       
  1169     file.Format( _L("%S%S"), &KCDrive, &confPath );    
       
  1170     CleanupStack::PopAndDestroy( relativePath );
       
  1171             
       
  1172     // If there was an existing configuration folder
       
  1173     if( BaflUtils::FileExists( iFsSession, file ) )
       
  1174         {
       
  1175         // Remove the old configuration
       
  1176         CFileMan* fileMan = CFileMan::NewL( iFsSession );
       
  1177         CleanupStack::PushL( fileMan );
       
  1178         User::LeaveIfError( fileMan->RmDir( file ) );
       
  1179         CleanupStack::PopAndDestroy( fileMan );    
       
  1180         }                                
       
  1181     
       
  1182     iThemeServer.UpdateHeaderListCache(
       
  1183             EhspsCacheRemoveHeader,        
       
  1184             aOdt.RootUid(),
       
  1185             aOdt.ProviderUid(),
       
  1186             aOdt.ThemeUid() );            
       
  1187      }
       
  1188     
       
  1189 
       
  1190 // -----------------------------------------------------------------------------
       
  1191 // ChspsInstallationHandler::RollBackL()
       
  1192 // Rolls back the installation if it fails or is cancelled. Functionality depends
       
  1193 // on the state where the installation was.
       
  1194 // (other items were commented in a header).
       
  1195 // -----------------------------------------------------------------------------
       
  1196 //
       
  1197 void ChspsInstallationHandler::RollBackL(ChspsODT& aOdt)
       
  1198     {
       
  1199 #ifdef HSPS_LOG_ACTIVE  
       
  1200     if( iLogBus )
       
  1201         {
       
  1202         iLogBus->LogText( _L( "hspsInstallationHandler::RollBackL(): - rolling back.." ) );
       
  1203         }
       
  1204 #endif    
       
  1205     
       
  1206     // then rolling back the installation in according to in which state it was before cancel
       
  1207     switch ( iInstallationPhase )
       
  1208         {
       
  1209         case EhspsPhaseIdle:                
       
  1210         case EhspsPhaseInitialise:
       
  1211         case EhspsPhaseCleanup:
       
  1212             break;        
       
  1213         case EhspsPhaseInstallSkeleton:        
       
  1214             {
       
  1215             iDefinitionRepository.RemoveThemeL( aOdt );
       
  1216             iInstallationPhase = EhspsPhaseIdle; // roll-back is completed
       
  1217             }
       
  1218             break;
       
  1219         default:
       
  1220             break;
       
  1221         }
       
  1222     }
       
  1223 
       
  1224 
       
  1225 // -----------------------------------------------------------------------------
       
  1226 // ChspsInstallationHandler::CompleteRequestL()
       
  1227 // Completes client request
       
  1228 // (other items were commented in a header).
       
  1229 // -----------------------------------------------------------------------------
       
  1230 //    
       
  1231 void ChspsInstallationHandler::CompleteRequestL(const ThspsServiceCompletedMessage aReturnMessage, 
       
  1232     const TDesC8& aHeaderData )
       
  1233     {
       
  1234     TBool wasLocked( EFalse );
       
  1235         
       
  1236     if( iDefinitionRepository.Locked() )
       
  1237         {
       
  1238         CleanupStack::PushL( TCleanupItem( UnlockRepository, &iDefinitionRepository ) );
       
  1239         wasLocked = ETrue;
       
  1240         }
       
  1241         
       
  1242     // only EhspsInstallThemeSuccess and EhspsInstallPhaseSuccess quaranties valid header to be returned
       
  1243     TBool complete( ETrue );
       
  1244     
       
  1245     switch( iInstallationMode )
       
  1246         {
       
  1247         case EServiceHandler:
       
  1248             {
       
  1249             if( aReturnMessage == EhspsInstallThemeSuccess  )
       
  1250                 {
       
  1251                 // Activate the installed application configuration if EhspsThemeStatusMakeActive is set                
       
  1252                 if ( iThemeStatus & EhspsThemeStatusMakeActive )
       
  1253                     {
       
  1254                     if ( iConfigurationType == EhspsAppConfiguration )
       
  1255                         {
       
  1256                         ActivateThemeL();
       
  1257                         }
       
  1258                     }
       
  1259                     
       
  1260                 // lets try to delete temp files. Server will delete them only 
       
  1261                 // if there are not current resource holders  
       
  1262                 iInstallationPhase = EhspsPhaseIdle;                           
       
  1263                 // write the result
       
  1264                 iResult->iIntValue1 = 0;
       
  1265                 iResult->iIntValue2 = 0;
       
  1266                 
       
  1267                 iDefinitionRepository.Unlock();
       
  1268                 
       
  1269                 if ( !iDisableNotifications )
       
  1270                     {
       
  1271                     // Inform server that a configuration was added or replaced and that the 
       
  1272                     // header cache should be updated (specific header to be added can be obtained
       
  1273                     // from the uids)
       
  1274                     
       
  1275                     if( iInstallationType == EInstallationTypeNew )
       
  1276                         {
       
  1277                         ThspsRepositoryInfo info( 
       
  1278                             ThspsRepositoryEvent( EhspsODTAdded ),
       
  1279                             0,
       
  1280                             0,
       
  1281                             0, //=Any file
       
  1282                             0,
       
  1283                             iOdt->RootUid(),
       
  1284                             iOdt->ProviderUid(),
       
  1285                             iOdt->ThemeUid(),0,ETrue,
       
  1286                             iOdt->ThemeFullName(),
       
  1287                             (TLanguage)( iOdt->OdtLanguage() )
       
  1288                             );
       
  1289                         
       
  1290                         iDefinitionRepository.RegisterNotification( info );
       
  1291                         }
       
  1292                     else if( iInstallationType == EInstallationTypeUpdate )
       
  1293                         {                        
       
  1294                         NotifyOdtUpdatedL();                                                
       
  1295                         }
       
  1296                     }
       
  1297                 
       
  1298 #ifdef HSPS_LOG_ACTIVE  
       
  1299                 if( iLogBus )
       
  1300                     {
       
  1301                     iLogBus->LogText( _L( "ChspsInstallationHandler::CompleteRequestL(): - configuration %d was successfully installed (EServiceHandler)" ),
       
  1302                             iOdt->ThemeUid() );
       
  1303                     }
       
  1304 #endif    
       
  1305                 }
       
  1306             else if ( aReturnMessage == EhspsInstallPhaseSuccess  )
       
  1307                 {
       
  1308                 iResult->iIntValue1 = iInstallationPhase;
       
  1309                 }
       
  1310             else if ( aReturnMessage == EhspsServiceRequestSheduled )
       
  1311                 {
       
  1312                 complete = EFalse;
       
  1313                 }
       
  1314             else if (aReturnMessage == EhspsServiceRequestCanceled)
       
  1315                 {
       
  1316                 iDefinitionRepository.Unlock();                 
       
  1317                 }
       
  1318             else
       
  1319                 {
       
  1320                 // installation failed, resetting
       
  1321                 // system error and xuikon error are writen in iResult when error was encountered
       
  1322                 iInstallationPhase = EhspsPhaseIdle;
       
  1323                 
       
  1324                 if( !iMessagePtr.IsNull() )
       
  1325                     {
       
  1326                     iMessagePtr.WriteL( 2, KNullDesC8, 0 );
       
  1327                     }
       
  1328                     
       
  1329                 RollBackL ( *iOdt );
       
  1330                 iDefinitionRepository.Unlock();    
       
  1331                 }
       
  1332                
       
  1333                if( complete && !iMessagePtr.IsNull() )
       
  1334                 {
       
  1335                 RDesWriteStream writeBuf( iResultData );
       
  1336                 iResult->ExternalizeL( writeBuf );
       
  1337                 writeBuf.Close();
       
  1338                 iMessagePtr.WriteL( 0, iResultData, 0 );
       
  1339                 iMessagePtr.WriteL( 2, aHeaderData, 0 ); 
       
  1340                 iMessagePtr.Complete( aReturnMessage );    
       
  1341                 } 
       
  1342             }
       
  1343             break;
       
  1344                 
       
  1345         case EAsynchronousObject:
       
  1346             {
       
  1347             if( aReturnMessage == EhspsInstallThemeSuccess  )
       
  1348                 {
       
  1349                 
       
  1350                 // Activate the installed application configuration if EhspsThemeStatusMakeActive is set
       
  1351                 if( iThemeStatus & EhspsThemeStatusMakeActive )
       
  1352                     {
       
  1353                     if ( iConfigurationType == EhspsAppConfiguration )
       
  1354                         {
       
  1355                         ActivateThemeL();
       
  1356                         }
       
  1357                     }
       
  1358                                                            
       
  1359                 // lets try to delete temp files. Server will delete them only if there are not
       
  1360                 // current resource holders  
       
  1361                 iInstallationPhase = EhspsPhaseIdle;
       
  1362                 iDefinitionRepository.Unlock();    
       
  1363                 
       
  1364                 if ( !iDisableNotifications )
       
  1365                     {
       
  1366                     if( iInstallationType == EInstallationTypeNew )
       
  1367                         {
       
  1368                         // Inform server there are files to be cleaned and cache has been updated
       
  1369                         ThspsRepositoryInfo info( ThspsRepositoryEvent( EhspsODTAdded ),
       
  1370                                     0,
       
  1371                                     0,
       
  1372                                     0, //=Any file
       
  1373                                     0,
       
  1374                                     iOdt->RootUid(),
       
  1375                                     iOdt->ProviderUid(),
       
  1376                                     iOdt->ThemeUid(),0,ETrue,
       
  1377                                     iOdt->ThemeFullName(),
       
  1378                                     (TLanguage)( iOdt->OdtLanguage() ) );
       
  1379                                     
       
  1380                         iDefinitionRepository.RegisterNotification( info );
       
  1381                         }
       
  1382                     else if( iInstallationType == EInstallationTypeUpdate )
       
  1383                         {                        
       
  1384                         NotifyOdtUpdatedL();                                                
       
  1385                         }                        
       
  1386                     }
       
  1387 
       
  1388 #ifdef HSPS_LOG_ACTIVE  
       
  1389                 if( iLogBus )
       
  1390                     {
       
  1391                     iLogBus->LogText( _L( "ChspsInstallationHandler::CompleteRequestL(): - configuration %d was successfully installed (EAsynchronousObject)" ),
       
  1392                             iOdt->ThemeUid() );
       
  1393                     }
       
  1394 #endif
       
  1395                 }
       
  1396             else if( aReturnMessage == EhspsInstallPhaseSuccess  )
       
  1397                 {
       
  1398                 iResult->iIntValue1 = iInstallationPhase;
       
  1399                 }
       
  1400             else if( aReturnMessage == EhspsServiceRequestSheduled )
       
  1401                 {
       
  1402                 complete = EFalse;
       
  1403                 }
       
  1404             else
       
  1405                 {
       
  1406                 // installation failed, resetting
       
  1407                 // system error and xuikon error are written in iResult when error was encountered
       
  1408                 iInstallationPhase = EhspsPhaseIdle;
       
  1409                 RollBackL ( *iOdt );
       
  1410                 iDefinitionRepository.Unlock();    
       
  1411                 }
       
  1412        
       
  1413             if ( complete )
       
  1414                 {                                
       
  1415                 User::RequestComplete( iRequestStatus, (TInt)aReturnMessage );                 
       
  1416                 }
       
  1417             }
       
  1418             break;        
       
  1419         default:
       
  1420             {
       
  1421             if( wasLocked )
       
  1422                 {
       
  1423                 CleanupStack::Pop( &iDefinitionRepository );
       
  1424                 }
       
  1425                 
       
  1426                User::Leave( KErrCancel );
       
  1427             }
       
  1428             break;
       
  1429         }
       
  1430         
       
  1431     if( wasLocked )
       
  1432         {
       
  1433         CleanupStack::Pop( &iDefinitionRepository );
       
  1434         }    
       
  1435     }
       
  1436 
       
  1437 // -----------------------------------------------------------------------------
       
  1438 // ChspsInstallationHandler::IsPluginUsedInAppConfsL
       
  1439 // -----------------------------------------------------------------------------
       
  1440 //
       
  1441 TBool ChspsInstallationHandler::IsPluginUsedInAppConfsL()
       
  1442     {
       
  1443     TBool isUsed = EFalse;
       
  1444     
       
  1445     const TInt KArrayGranularity = 3;
       
  1446     CArrayPtrSeg<ChspsODT>* activeAppConfs =  new ( ELeave ) CArrayPtrSeg<ChspsODT>( KArrayGranularity );
       
  1447     CleanupStack::PushL( activeAppConfs );
       
  1448 
       
  1449     // Retrieve active application configurations. These are not owned!
       
  1450     GetActiveAppConfsL( *activeAppConfs );
       
  1451                             
       
  1452     // Loop found headers
       
  1453     for( TInt i = 0; i < activeAppConfs->Count(); i++ )
       
  1454         {
       
  1455         ChspsODT* const header = (*activeAppConfs)[i];       
       
  1456         if( header )
       
  1457             {                                        
       
  1458             // Clone header to avoid modification of original
       
  1459             ChspsODT* odt = header->CloneL();
       
  1460             CleanupStack::PushL( odt );
       
  1461             
       
  1462             // Get full ODT instance with DOM data       
       
  1463             User::LeaveIfError( iDefinitionRepository.GetOdtL( *odt ) );
       
  1464             
       
  1465             // Get all plugin instances with the configuration UID that was just installed
       
  1466             RArray<TInt> pluginIds;
       
  1467             CleanupClosePushL( pluginIds );                            
       
  1468             hspsServerUtil::GetPluginIdsByUidL( 
       
  1469                     *odt,
       
  1470                     TUid::Uid( iThemeUid ),
       
  1471                     pluginIds );            
       
  1472             isUsed = ( pluginIds.Count() > 0 );                                   
       
  1473             CleanupStack::PopAndDestroy(); // pluginIds
       
  1474             
       
  1475             CleanupStack::PopAndDestroy( odt );
       
  1476             
       
  1477             if ( isUsed )                
       
  1478                 {                               
       
  1479                 break;
       
  1480                 }                             
       
  1481             }
       
  1482         }
       
  1483     
       
  1484      
       
  1485     
       
  1486     CleanupStack::PopAndDestroy( activeAppConfs );
       
  1487     
       
  1488     return isUsed;
       
  1489     }
       
  1490 
       
  1491 // -----------------------------------------------------------------------------
       
  1492 // ChspsInstallationHandler::NotifyOdtUpdatedL
       
  1493 // -----------------------------------------------------------------------------
       
  1494 //
       
  1495 void ChspsInstallationHandler::NotifyOdtUpdatedL()
       
  1496     {    
       
  1497     // Nothing to do if notifications disabled.
       
  1498     if( iDisableNotifications )
       
  1499         {        
       
  1500         return;
       
  1501         }    
       
  1502 
       
  1503     // This method should only be called when type is update.
       
  1504     if( iInstallationType != EInstallationTypeUpdate )
       
  1505         {
       
  1506 #ifdef HSPS_LOG_ACTIVE  
       
  1507         if( iLogBus )
       
  1508             {
       
  1509             iLogBus->LogText( _L( "ChspsInstallationHandler::NotifyOdtUpdatedL(): Error: Installation type is not update." ) );
       
  1510             }
       
  1511 #endif
       
  1512         
       
  1513         return;
       
  1514         }    
       
  1515     
       
  1516     // Sanity check.
       
  1517     if( !iOdt )
       
  1518         {
       
  1519 #ifdef HSPS_LOG_ACTIVE  
       
  1520         if( iLogBus )
       
  1521             {
       
  1522             iLogBus->LogText( _L( "ChspsInstallationHandler::NotifyOdtUpdatedL(): Error: iOdt == NULL." ) );
       
  1523             }
       
  1524 #endif
       
  1525         
       
  1526         return;
       
  1527         }
       
  1528                   
       
  1529     const TInt KArrayGranularity = 2;
       
  1530     CArrayPtrSeg<ChspsODT>* activeAppConfs =  new ( ELeave ) CArrayPtrSeg<ChspsODT>( KArrayGranularity );
       
  1531     CleanupStack::PushL( activeAppConfs );
       
  1532 
       
  1533     // Retrieve active application configurations. These are not owned!
       
  1534     GetActiveAppConfsL( *activeAppConfs );
       
  1535 
       
  1536     // Notification list.
       
  1537     RArray<ThspsRepositoryInfo> notifications;
       
  1538     CleanupClosePushL( notifications );    
       
  1539     
       
  1540     // Construct notifications for every changed plugin id
       
  1541     // in every active application configuration.
       
  1542     for( TInt i = 0; i < activeAppConfs->Count(); i++ )
       
  1543         {
       
  1544         ChspsODT* const activeODT = (*activeAppConfs)[i];
       
  1545         
       
  1546         // Sanity check.
       
  1547         if( !activeODT )
       
  1548             {
       
  1549 #ifdef HSPS_LOG_ACTIVE  
       
  1550             if( iLogBus )
       
  1551                 {
       
  1552                 iLogBus->LogText( _L( "ChspsInstallationHandler::NotifyOdtUpdatedL(): Error: active ODT list contains NULL." ) );
       
  1553                 }
       
  1554 #endif
       
  1555         
       
  1556             continue;
       
  1557             }
       
  1558         
       
  1559         // Clone activeOdt to avoid modification of original.
       
  1560         ChspsODT* fullODT = activeODT->CloneL();
       
  1561         CleanupStack::PushL( fullODT );
       
  1562 
       
  1563         User::LeaveIfError( iDefinitionRepository.GetOdtL( *fullODT ) );
       
  1564         
       
  1565         RArray<TInt> pluginIds;
       
  1566         CleanupClosePushL( pluginIds );
       
  1567 
       
  1568         // Get plugin ids.
       
  1569         hspsServerUtil::GetPluginIdsByUidL( *fullODT,
       
  1570                                             TUid::Uid( iOdt->ThemeUid() ),
       
  1571                                             pluginIds );
       
  1572         
       
  1573         // Construct notifications. One for each plugin instance
       
  1574         // that is affected by update.
       
  1575         for( TInt j = 0; j < pluginIds.Count(); j++ )
       
  1576             {
       
  1577             ThspsRepositoryInfo info( 
       
  1578                 ThspsRepositoryEvent( EhspsODTUpdated ),
       
  1579                 fullODT->RootUid(),
       
  1580                 fullODT->ThemeUid(),
       
  1581                 0, //=Any file
       
  1582                 0,
       
  1583                 iOdt->RootUid(),
       
  1584                 iOdt->ProviderUid(),
       
  1585                 iOdt->ThemeUid(),
       
  1586                 pluginIds[j], 
       
  1587                 EFalse,
       
  1588                 KNullDesC(),
       
  1589                 (TLanguage)( fullODT->OdtLanguage() ) );
       
  1590             
       
  1591             notifications.Append( info );
       
  1592             }        
       
  1593         
       
  1594         CleanupStack::PopAndDestroy(); // pluginIds.
       
  1595         CleanupStack::PopAndDestroy( fullODT );
       
  1596         fullODT = NULL;
       
  1597         
       
  1598         // Send applications notifications in one group.
       
  1599         for( TInt k = 0; k < notifications.Count(); k++ )
       
  1600             {
       
  1601             // If last...
       
  1602             if( k == notifications.Count() - 1 )
       
  1603                 {
       
  1604                 // ... Modify accordingly.
       
  1605                 notifications[ k ].iLastNotification = ETrue;
       
  1606                 }
       
  1607             
       
  1608             // Send.
       
  1609             iDefinitionRepository.RegisterNotification( notifications[ k ] );        
       
  1610             }
       
  1611         
       
  1612         // Clean notifications list.
       
  1613         notifications.Reset();
       
  1614         }
       
  1615     
       
  1616     CleanupStack::PopAndDestroy(); // notifications.    
       
  1617     CleanupStack::PopAndDestroy( activeAppConfs );
       
  1618     activeAppConfs = NULL;
       
  1619     }                        
       
  1620 
       
  1621 // -----------------------------------------------------------------------------
       
  1622 // ChspsInstallationHandler::GetActiveAppConfsL
       
  1623 // -----------------------------------------------------------------------------
       
  1624 //    
       
  1625 void ChspsInstallationHandler::GetActiveAppConfsL( CArrayPtrSeg<ChspsODT>& aActiveAppConfs )
       
  1626     {
       
  1627     const TInt count = iHeaderListCache.Count();
       
  1628     for( TInt i = 0; i < count; i++ )
       
  1629         {
       
  1630         ChspsODT* header = iHeaderListCache.At( i );
       
  1631         
       
  1632         if( header && header->ConfigurationType() == EhspsAppConfiguration )
       
  1633             {
       
  1634             // Check if application configuration is active.            
       
  1635             TInt tmp = 0;            
       
  1636             if ( iCentralRepository.Get( header->RootUid(), tmp ) == KErrNone )
       
  1637                 {
       
  1638                 if( tmp == header->ThemeUid() )
       
  1639                     {
       
  1640                     // Active application configuration found.
       
  1641                     aActiveAppConfs.AppendL( header );
       
  1642                     } 
       
  1643                 } 
       
  1644             }
       
  1645         }
       
  1646     }
       
  1647 
       
  1648 // -----------------------------------------------------------------------------
       
  1649 // Saves ODT itself as an resource
       
  1650 // -----------------------------------------------------------------------------
       
  1651 //    
       
  1652 void ChspsInstallationHandler::SetODTAsResourceL( ChspsODT& aOdt )
       
  1653     {
       
  1654     TInt errorCode = KErrNone;
       
  1655     
       
  1656     ChspsResource* res = ChspsResource::NewL();
       
  1657     CleanupStack::PushL( res );
       
  1658     
       
  1659     ThspsLockingPolicy lockingPolicy = EhspsUnlocked;
       
  1660     if ( aOdt.Flags() & EhspsThemeStatusLicenceeDefault )
       
  1661         {
       
  1662         lockingPolicy = EhspsLocked;
       
  1663         }
       
  1664         
       
  1665     // ODT-resource is handled as a cached resource                 
       
  1666     res->SetLockingPolicy( lockingPolicy );
       
  1667     res->SetResourceType( EResourceODT );    
       
  1668     res->SetResourceIdL( aOdt.ThemeShortName() );
       
  1669     //res->SetFileNameL( filepath ); will be set by the repository       
       
  1670     res->SetMimeTypeL(TDataType( KUnknownMimeType ));
       
  1671     res->SetConfigurationUid( aOdt.ThemeUid() );
       
  1672     
       
  1673     // Creates a path for given ODT
       
  1674     iDefinitionRepository.MakeODTPathL( aOdt, *res );
       
  1675         
       
  1676     aOdt.AddResourceL( res );
       
  1677     
       
  1678     CleanupStack::Pop(res);   
       
  1679             
       
  1680     User::LeaveIfError( errorCode );
       
  1681     }
       
  1682 
       
  1683 
       
  1684 // -----------------------------------------------------------------------------
       
  1685 // ChspsInstallationHandler::ActivateThemeL()
       
  1686 // 
       
  1687 // (other items were commented in a header).
       
  1688 // -----------------------------------------------------------------------------
       
  1689 //
       
  1690 void ChspsInstallationHandler::ActivateThemeL()
       
  1691     {
       
  1692     const TUint32 fullMask = 0xFFFFFFFF;
       
  1693     RArray<TUint32> res;
       
  1694     CleanupClosePushL( res );
       
  1695     
       
  1696     TInt errorCode = KErrNone;
       
  1697     iCentralRepository.FindL( iOdt->RootUid(), fullMask, res );
       
  1698        if ( res.Count() == 0 )
       
  1699         { 
       
  1700         errorCode = iCentralRepository.Create( iOdt->RootUid(), iOdt->ThemeUid() );
       
  1701         }
       
  1702     else
       
  1703         {
       
  1704         errorCode = iCentralRepository.Set( iOdt->RootUid(), iOdt->ThemeUid() );
       
  1705         }
       
  1706     if ( !errorCode )
       
  1707         {
       
  1708         TUint flags = iOdt->Flags();
       
  1709         iOdt->SetFlags( flags | EhspsThemeStatusActive );
       
  1710         
       
  1711         // If not processing ROM installations
       
  1712         if ( !iDisableNotifications )
       
  1713             {
       
  1714             // inform for cache update to the repository so that everyone will know 
       
  1715             // about the change
       
  1716             ThspsRepositoryInfo info( EhspsODTActivated );
       
  1717             iDefinitionRepository.RegisterNotification( info );
       
  1718             }
       
  1719         }
       
  1720     res.Close();    
       
  1721     CleanupStack::PopAndDestroy(); //res
       
  1722     }
       
  1723         
       
  1724 // -----------------------------------------------------------------------------
       
  1725 // ChspsInstallationHandler::OnStartElementL
       
  1726 // Verifies that the installer is able to parse the manifest file, 
       
  1727 // parses language specifications and resources 
       
  1728 // -----------------------------------------------------------------------------
       
  1729 //
       
  1730  void ChspsInstallationHandler::OnStartElementL(
       
  1731         const RTagInfo& aElement, 
       
  1732         const RAttributeArray& aAttributes, 
       
  1733         TInt /*aErrorCode*/)
       
  1734     {
       
  1735     TPtrC8 localName = aElement.LocalName().DesC();
       
  1736 
       
  1737     if( iContent )
       
  1738         {
       
  1739         delete iContent;
       
  1740         iContent = NULL;
       
  1741         }
       
  1742     
       
  1743     if ( localName == KPackage )
       
  1744         {
       
  1745         // Check whether the version attribute is specified
       
  1746         TInt argCount = aAttributes.Count();
       
  1747         if( argCount )
       
  1748             {
       
  1749             for( TInt argIndex=0; argIndex < argCount; argIndex++ )
       
  1750                 {                            
       
  1751                 const TDesC8& attName = aAttributes[argIndex].Attribute().LocalName().DesC();
       
  1752                 if ( attName.Compare(KPackageVersion) == 0 )
       
  1753                     {
       
  1754                     delete iPackageVersion;
       
  1755                     iPackageVersion = NULL;
       
  1756                     iPackageVersion = HBufC::NewL( KMaxFileName );
       
  1757                     iPackageVersion->Des().Copy( aAttributes[argIndex].Value().DesC() );
       
  1758                     // Is manifest supported by this parser?
       
  1759                     iPackageVerSupported = EFalse;
       
  1760                     if ( iPackageVersion->Des().Compare( KhspsSupportedManifestVersion ) == 0 )
       
  1761                         {
       
  1762                         iPackageVerSupported = ETrue;
       
  1763                         }
       
  1764                     break;
       
  1765                     }
       
  1766                 }
       
  1767             }
       
  1768         }
       
  1769     
       
  1770     else if ( localName == KLocalized )
       
  1771         {
       
  1772         // From now on, we are parsing filenames of localized resources
       
  1773         iLocalized = ETrue;
       
  1774         }
       
  1775          
       
  1776     else if ( localName == KFileResource )
       
  1777         {                    
       
  1778         if ( iMediaType )
       
  1779             {
       
  1780             delete iMediaType;
       
  1781             iMediaType = NULL;
       
  1782             }
       
  1783         
       
  1784         // Get attributes of the resource element and store them for adding in ::OnEndElementL()   
       
  1785         TInt attrCount( aAttributes.Count() );
       
  1786         for( TInt i=0; i<attrCount; i++ )
       
  1787             {
       
  1788             const TDesC8& attValueDes8 = aAttributes[i].Value().DesC();                
       
  1789             
       
  1790             // If mediatype attribute was found
       
  1791             if ( aAttributes[i].Attribute().LocalName().DesC() == KMediaType )
       
  1792                 {                                                
       
  1793                 TPtrC8 orginalPtr( aAttributes[i].Value().DesC() );
       
  1794                 TInt length = orginalPtr.Length();
       
  1795                 
       
  1796                 // Length limit
       
  1797                 if ( length > KMaxMediaTypeLength )
       
  1798                     {
       
  1799                     length = KMaxMediaTypeLength;
       
  1800                     
       
  1801 #ifdef HSPS_LOG_ACTIVE  
       
  1802                     if( iLogBus )
       
  1803                         {
       
  1804                         iLogBus->LogText( _L( "ChspsInstallationHandler::OnStartElementL(): - mediatype was too long!" ) );
       
  1805                         }
       
  1806 #endif    
       
  1807                     }                                                        
       
  1808                     
       
  1809                 iMediaType = HBufC8::NewL( length );
       
  1810                 iMediaType->Des().Copy( orginalPtr.Left( length ) );
       
  1811                 }
       
  1812             else if ( aAttributes[i].Attribute().LocalName().DesC() == KTag )
       
  1813                 {                
       
  1814                 delete iResourceTag;
       
  1815                 iResourceTag = NULL;
       
  1816                 if ( attValueDes8.Length() )
       
  1817                     {
       
  1818                     iResourceTag = attValueDes8.Left( KMaxTagsLength ).AllocL();                    
       
  1819                     }
       
  1820                 }
       
  1821             
       
  1822             } // for
       
  1823                 
       
  1824         }
       
  1825     
       
  1826     if ( !iMultiInstanceFound )
       
  1827         {
       
  1828         iMultiInstance = KMultiInstanceDefaultValue;
       
  1829         }
       
  1830     }
       
  1831   
       
  1832 // -----------------------------------------------------------------------------
       
  1833 // Parsing of the manifest elements.
       
  1834 // -----------------------------------------------------------------------------
       
  1835 //
       
  1836 void ChspsInstallationHandler::OnEndElementL( const RTagInfo& aElement, TInt /*aErrorCode*/ )
       
  1837     {
       
  1838     TPtrC8 localName = aElement.LocalName().DesC();
       
  1839     
       
  1840     if ( localName == KFamily )
       
  1841         {
       
  1842         const TPtrC8 familyPtr( iContent->Des() );        
       
  1843         iFamilyMask |= ChspsFamily::GetFamilyType( familyPtr );
       
  1844         }    
       
  1845     else if ( localName == KConfigurationType )
       
  1846         {
       
  1847         // Get configuration type from the manifest
       
  1848         if( *iContent == KManifestTypeApp )
       
  1849             {
       
  1850             iConfigurationType = EhspsAppConfiguration;
       
  1851             }
       
  1852         else if ( *iContent == KManifestTypeView )
       
  1853             {
       
  1854             iConfigurationType = EhspsViewConfiguration;
       
  1855             }
       
  1856         else if ( *iContent == KManifestTypeWidget )
       
  1857             {
       
  1858             iConfigurationType = EhspsWidgetConfiguration;
       
  1859             }
       
  1860          else if( *iContent == KManifestTypeTemplate )
       
  1861             {            
       
  1862             iConfigurationType = EhspsTemplateConfiguration;            
       
  1863             }        
       
  1864          else
       
  1865              {
       
  1866              User::Leave( KErrNotSupported );
       
  1867              }
       
  1868         }
       
  1869     else if ( localName == KInterfaceUid )
       
  1870         {
       
  1871         if( iContent )
       
  1872             {
       
  1873             // Delete extra whitespaces.
       
  1874             iContent->Des().TrimAll();
       
  1875             
       
  1876             // Convert to Uint.
       
  1877             User::LeaveIfError( hspsServerUtil::HexString2Uint( *iContent, iRootUid ) );
       
  1878             ApplyUidRangeTestsL( iRootUid );
       
  1879             }
       
  1880         }
       
  1881     else if ( localName == KProviderUid )
       
  1882         {
       
  1883         if( iContent )
       
  1884             {
       
  1885             // Delete extra whitespaces.
       
  1886             iContent->Des().TrimAll();
       
  1887 
       
  1888             // Convert to Uint.
       
  1889             User::LeaveIfError( hspsServerUtil::HexString2Uint( *iContent, iProviderUid ) );                        
       
  1890             ApplyUidRangeTestsL( iProviderUid );
       
  1891             }
       
  1892         }
       
  1893     else if ( localName == KThemeUid )
       
  1894         {
       
  1895         if( iContent )
       
  1896             {        
       
  1897             // Delete extra whitespaces.
       
  1898             iContent->Des().TrimAll();
       
  1899 
       
  1900             // Convert to Uint.
       
  1901             User::LeaveIfError( hspsServerUtil::HexString2Uint( *iContent, iThemeUid ) );            
       
  1902             ApplyUidRangeTestsL( iThemeUid );
       
  1903             }
       
  1904         }
       
  1905     else if ( localName == KThemeStatus )
       
  1906         {
       
  1907         if( *iContent == KStatusNone )
       
  1908             {
       
  1909             iThemeStatus = iThemeStatus | EhspsThemeStatusNone;
       
  1910             }
       
  1911          else if( *iContent == KStatusLicenceeDefault )
       
  1912             {
       
  1913             iThemeStatus = iThemeStatus | EhspsThemeStatusLicenceeDefault;
       
  1914             }
       
  1915          else if( *iContent == KStatusLicenceeRestorable )
       
  1916             {
       
  1917             iThemeStatus = iThemeStatus | EhspsThemeStatusLicenceeRestorable;
       
  1918             iThemeStatus = iThemeStatus | EhspsThemeStatusLicenceeDefault;
       
  1919             }
       
  1920          else if( *iContent == KStatusOperatorDefault )
       
  1921             {
       
  1922             iThemeStatus = iThemeStatus | EhspsThemeStatusOperatorDefault;
       
  1923             }
       
  1924          else if( *iContent == KStatusUserDefault )
       
  1925             {
       
  1926             iThemeStatus = iThemeStatus | EhspsThemeStatusUserDefault;
       
  1927             }
       
  1928         else if( *iContent == KStatusMakeActive )
       
  1929             {
       
  1930             iThemeStatus = iThemeStatus | EhspsThemeStatusMakeActive;
       
  1931             }
       
  1932         else if( *iContent == KStatusLocked )
       
  1933             {
       
  1934             iThemeStatus = iThemeStatus | EhspsThemeStatusLocked;
       
  1935             }
       
  1936         }
       
  1937     else if ( localName == KThemeFullName )
       
  1938         {
       
  1939         // Store value of the parsed "fullname" element
       
  1940         if ( iThemeFullName )
       
  1941             {
       
  1942             delete iThemeFullName;
       
  1943             iThemeFullName = NULL;
       
  1944             }
       
  1945         iThemeFullName = HBufC::NewL( KMaxFileName );
       
  1946         TInt contentLength = iContent->Des().Length(); 
       
  1947         if ( contentLength > KMaxFileName )
       
  1948             {
       
  1949             contentLength = KMaxFileName;
       
  1950             }
       
  1951         TPtr ptr( iThemeFullName->Des() );
       
  1952         ptr.Copy( iContent->Des().Left(contentLength) );                                           
       
  1953         }
       
  1954     else if ( localName == KThemeShortName )
       
  1955         {
       
  1956         delete iThemeShortName;
       
  1957         iThemeShortName = NULL;
       
  1958         iThemeShortName = HBufC8::NewL( KMaxFileName );
       
  1959         TPtr8 themeShortNameDes( iThemeShortName->Des() );
       
  1960         themeShortNameDes = *iContent;
       
  1961         }
       
  1962     else if ( localName == KThemeVersion )
       
  1963         {
       
  1964         delete iThemeVersion;
       
  1965         iThemeVersion = NULL;
       
  1966         iThemeVersion = HBufC8::NewL( KMaxFileName );
       
  1967         TPtr8 themeVersionDes( iThemeVersion->Des() );
       
  1968         themeVersionDes = *iContent;               
       
  1969         }
       
  1970     else if ( localName == KThemeDesc )
       
  1971         {        
       
  1972         if ( iContent )
       
  1973             {
       
  1974             delete iThemeDesc;
       
  1975             iThemeDesc = NULL;
       
  1976             iThemeDesc = HBufC8::NewL( KMaxDescLength );        
       
  1977             TPtr8 descPtr8( iThemeDesc->Des() );
       
  1978             descPtr8.Copy( (*iContent).Left( KMaxDescLength ) );        
       
  1979             }
       
  1980         }
       
  1981     else if ( localName == KFileLogo )
       
  1982         {
       
  1983         if ( iContent )
       
  1984             {            
       
  1985             // Get possible file references and add them to the  
       
  1986             // resource array with a logo tag
       
  1987             HBufC* result = NULL;
       
  1988             ParseIconDeclarationL( 
       
  1989                     *iContent, 
       
  1990                     KObjectAttrTagLogo,
       
  1991                     result );
       
  1992             if ( result )
       
  1993                 {
       
  1994                 // Store logo declaration
       
  1995                 CleanupStack::PushL( result );
       
  1996                 iOdt->SetLogoFileL( *result );
       
  1997                 CleanupStack::PopAndDestroy();
       
  1998                 }
       
  1999             }
       
  2000         }
       
  2001     else if ( localName == KFilePreview )
       
  2002         {
       
  2003         if ( iContent )
       
  2004             {            
       
  2005             // Get possible file references and add them to the  
       
  2006             // resource array with a preview tag
       
  2007             HBufC* result = NULL;
       
  2008             ParseIconDeclarationL( 
       
  2009                     *iContent, 
       
  2010                     KObjectAttrTagPreview,
       
  2011                     result
       
  2012                     );            
       
  2013             if ( result )
       
  2014                 {
       
  2015                 // Store preview declaration
       
  2016                 CleanupStack::PushL( result );
       
  2017                 iOdt->SetPreviewFileL( *result );
       
  2018                 CleanupStack::PopAndDestroy();
       
  2019                 }            
       
  2020             }
       
  2021         }
       
  2022     else if ( localName == KFileXML )
       
  2023         {
       
  2024         if( iContent )
       
  2025             {
       
  2026             // Convert from 8 to 16bit string
       
  2027             HBufC* nameBuf = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *iContent );                        
       
  2028             // Find full path to the file 
       
  2029             TFileName fullName;
       
  2030             hspsServerUtil::FindFile(
       
  2031                     iFsSession,                    
       
  2032                     iThemeFilePath, 
       
  2033                     nameBuf->Des(),
       
  2034                     iInstallFromUDAEmmc,
       
  2035                     fullName );
       
  2036             delete nameBuf;
       
  2037             nameBuf = NULL;
       
  2038             if( !fullName.Length() )
       
  2039                 {
       
  2040                 iFileNotFound = ETrue;
       
  2041                 iResult->iXuikonError = KErrXmlFileNotFound;
       
  2042                 User::Leave( KErrNotFound );
       
  2043                 }
       
  2044             delete iXmlFile;
       
  2045             iXmlFile = NULL;
       
  2046             iXmlFile = fullName.AllocL();
       
  2047             }
       
  2048         }
       
  2049     else if ( localName == KFileDTD )
       
  2050         {
       
  2051         // Parse name of the DTD files
       
  2052         if ( !iContent || iContent->Length() < 1 )
       
  2053             {
       
  2054             User::Leave( KErrArgument );
       
  2055             }
       
  2056         
       
  2057         if ( iDtdFile )
       
  2058             {
       
  2059             delete iDtdFile;
       
  2060             iDtdFile = 0;
       
  2061             }                
       
  2062         iDtdFile = HBufC::NewL( iContent->Length() );
       
  2063         iDtdFile->Des().Copy( iContent->Des() );                       
       
  2064         }    
       
  2065     else if ( localName == KFileResource )
       
  2066         {        
       
  2067         // Following attributes are parsed in OnStartElement callback
       
  2068         TPtrC8 mediaPtr;
       
  2069         if ( iMediaType )
       
  2070             {
       
  2071             mediaPtr.Set( iMediaType->Des() );
       
  2072             }
       
  2073         TPtrC8 tagsPtr;
       
  2074         if ( iResourceTag )
       
  2075             {
       
  2076             tagsPtr.Set( iResourceTag->Des() );
       
  2077             }
       
  2078                     
       
  2079         // Parse name of the resource file and make 8bit to 16bit conversion     
       
  2080         HBufC* fileName = CnvUtfConverter::ConvertToUnicodeFromUtf8L( *iContent );
       
  2081         if ( !fileName || fileName->Des().Length() < 1 )
       
  2082             {
       
  2083             User::Leave( KErrArgument );
       
  2084             }
       
  2085         CleanupStack::PushL( fileName );
       
  2086         
       
  2087         // If parsing localized resources
       
  2088         if ( iLocalized )
       
  2089             {                                        
       
  2090             // Add locale specific resources into temp array                        
       
  2091             AddResourceL(
       
  2092                 *iTempLocalizedResourceList,
       
  2093                 *fileName,
       
  2094                 ELangNone,        
       
  2095                 EResourceOther,
       
  2096                 mediaPtr,
       
  2097                 tagsPtr );    
       
  2098             }
       
  2099         else
       
  2100             {
       
  2101             // If Xuikon resource
       
  2102             TFileName interfacePath( GetInterfacePath() );
       
  2103             HBufC* resourceFile = NULL;
       
  2104             if( interfacePath.Length() )
       
  2105                 {
       
  2106                 _LIT(KSubFolder, "00\\");
       
  2107                 resourceFile = HBufC::NewLC( interfacePath.Length() + KSubFolder().Length() + fileName->Length() );
       
  2108                 resourceFile->Des().Copy( interfacePath );
       
  2109                 resourceFile->Des().Append( KSubFolder );
       
  2110                 resourceFile->Des().Append( *fileName );                
       
  2111                 }
       
  2112             else
       
  2113                 {
       
  2114                 resourceFile = HBufC::NewLC( iThemeFilePath.Length() + fileName->Length() );
       
  2115                 resourceFile->Des().Copy( iThemeFilePath );
       
  2116                 resourceFile->Des().Append( *fileName );
       
  2117                 }
       
  2118                                     
       
  2119             // Validate the file
       
  2120             if( !BaflUtils::FileExists( iFsSession, *resourceFile ) )
       
  2121                 {
       
  2122 #ifdef HSPS_LOG_ACTIVE  
       
  2123                 TBuf8<KMaxFileName> name8;
       
  2124                 name8.Copy( *resourceFile );
       
  2125                 if( iLogBus )
       
  2126                     {
       
  2127                     iLogBus->LogText( _L8( "ChspsInstallationHandler::OnEndElementL(): - resource file does not exist '%S'" ),
       
  2128                             &name8 );
       
  2129                     }
       
  2130 #endif            
       
  2131                 iFileNotFound = ETrue;
       
  2132                 iResult->iXuikonError = KErrResourceFileNotFound;
       
  2133                 }
       
  2134             
       
  2135             // Add common resources
       
  2136             AddResourceL(
       
  2137                 *iResourceList,
       
  2138                 *resourceFile,
       
  2139                 ELangNone,
       
  2140                 EResourceOther,
       
  2141                 mediaPtr,
       
  2142                 tagsPtr );
       
  2143             
       
  2144             CleanupStack::PopAndDestroy( resourceFile );         
       
  2145             }
       
  2146         
       
  2147         CleanupStack::PopAndDestroy( fileName );
       
  2148         
       
  2149         if ( iMediaType )
       
  2150             {
       
  2151             delete iMediaType;
       
  2152             iMediaType = NULL;
       
  2153             }
       
  2154         if ( iResourceTag )
       
  2155             {
       
  2156             delete iResourceTag;
       
  2157             iResourceTag = NULL;
       
  2158             }
       
  2159         }
       
  2160     else if ( localName == KMultiInstance)
       
  2161         {
       
  2162         iMultiInstanceFound = ETrue;
       
  2163         if( iContent )
       
  2164             {
       
  2165             // Delete extra whitespaces.
       
  2166             iContent->Des().TrimAll();
       
  2167             
       
  2168             // Convert to int
       
  2169             TLex8 lex( iContent->Des() );
       
  2170             TInt err = lex.Val( iMultiInstance );
       
  2171             // iContent is not a number - check for strings
       
  2172             if ( err != KErrNone )
       
  2173                 {
       
  2174                 if ( iContent->CompareF( KMultiInstanceUnlimited ) 
       
  2175                     == KErrNone )
       
  2176                     {
       
  2177                     iMultiInstance = KMultiInstanceUnlimitedValue;
       
  2178                     }
       
  2179                 else if ( iContent->CompareF( KMultiInstanceHidden ) == 
       
  2180                     KErrNone  )
       
  2181                     {
       
  2182                     iMultiInstance = KMultiInstanceHiddenValue;
       
  2183                     }
       
  2184                 else 
       
  2185                     {
       
  2186                     User::Leave( KErrArgument );
       
  2187                     }
       
  2188                 }
       
  2189             // iContent is a number - check whether it is valid
       
  2190             else
       
  2191                 {
       
  2192                 if ( ( iMultiInstance < KMultiInstanceMinimumCountValue ) || 
       
  2193                     ( iMultiInstance > KMultiInstanceMaximumCountValue ) )
       
  2194                     {
       
  2195                     User::Leave( KErrArgument );                    
       
  2196                     }
       
  2197                 }
       
  2198             }
       
  2199         }
       
  2200     }
       
  2201 
       
  2202 // -----------------------------------------------------------------------------
       
  2203 // The needed memory for each element information is reserved here.
       
  2204 // -----------------------------------------------------------------------------
       
  2205 //
       
  2206 void ChspsInstallationHandler::OnContentL(const TDesC8& aBytes, TInt aErrorCode)
       
  2207     {
       
  2208     if ( aErrorCode == KErrNone )
       
  2209         {
       
  2210         if ( !iContent )
       
  2211             {
       
  2212             iContent = HBufC8::NewL( aBytes.Size() );
       
  2213             *iContent = aBytes;
       
  2214             }
       
  2215         else
       
  2216             {
       
  2217             iContent = iContent->ReAllocL( iContent->Size() + aBytes.Size() );
       
  2218             TPtr8 c( iContent->Des() );
       
  2219             c.Append( aBytes );
       
  2220             }
       
  2221         }
       
  2222    
       
  2223     }
       
  2224 
       
  2225 // -----------------------------------------------------------------------------
       
  2226 // Disables "configuration was installed" notifications
       
  2227 // -----------------------------------------------------------------------------
       
  2228 //
       
  2229 void ChspsInstallationHandler::DisableNotifications()    
       
  2230     {
       
  2231     iDisableNotifications = ETrue;
       
  2232     }
       
  2233 
       
  2234 // -----------------------------------------------------------------------------
       
  2235 // Disables eclipsing from UDA and eMMC drives
       
  2236 // -----------------------------------------------------------------------------
       
  2237 //
       
  2238 void ChspsInstallationHandler::DisableUdaEmmcInstallations()
       
  2239     {
       
  2240     iInstallFromUDAEmmc = EFalse;
       
  2241     }
       
  2242 
       
  2243 // -----------------------------------------------------------------------------
       
  2244 // ChspsInstallationHandler::AddInterfaceResourcesV2L
       
  2245 // -----------------------------------------------------------------------------
       
  2246 //
       
  2247 void ChspsInstallationHandler::AddInterfaceResourcesV2L(
       
  2248         const TDesC& aPath )
       
  2249     {
       
  2250     // Retrieve supported localizations.
       
  2251     CArrayFixFlat<TInt>* systemEpocLanguageCodes = NULL;
       
  2252     hspsServerUtil::GetInstalledLanguagesL(
       
  2253             systemEpocLanguageCodes );
       
  2254     CleanupStack::PushL( systemEpocLanguageCodes );
       
  2255                             
       
  2256     // Find all entries under the Xuikon folders that
       
  2257     // match our eclipsing rules and localisations supported by phone.
       
  2258     RArray<TInt> driveArray;
       
  2259     CleanupClosePushL( driveArray );   
       
  2260     TInt drive = hspsServerUtil::GetEmmcDrivePath( iFsSession );
       
  2261     if ( drive != KErrNotFound )
       
  2262         {
       
  2263         driveArray.Append( drive );
       
  2264         }
       
  2265     
       
  2266     driveArray.Append( EDriveC );
       
  2267     driveArray.Append( EDriveZ );     
       
  2268     
       
  2269     FindResourceFilesL( aPath, ETrue, driveArray, systemEpocLanguageCodes );
       
  2270    
       
  2271     CleanupStack::PopAndDestroy(); // driveArray
       
  2272     CleanupStack::PopAndDestroy( systemEpocLanguageCodes );    
       
  2273     }    
       
  2274     
       
  2275 // -----------------------------------------------------------------------------
       
  2276 // Finds locale specific subdirectories and resources and appends those
       
  2277 // into the resource array 
       
  2278 // Should be executed prior to the CheckHeader method!
       
  2279 // -----------------------------------------------------------------------------
       
  2280 //
       
  2281 void ChspsInstallationHandler::AddLocalesL(
       
  2282         const TDesC& aPath,
       
  2283         const TBool aProcessOnlyDTD )
       
  2284     {
       
  2285     // Retrieve phone supported language.
       
  2286     CArrayFixFlat<TInt>* languageCodes = NULL;
       
  2287     hspsServerUtil::GetInstalledLanguagesL( languageCodes );
       
  2288     CleanupStack::PushL( languageCodes );     
       
  2289     
       
  2290     // Ensure that path contains '\' at the end.
       
  2291     TFileName pathBase;
       
  2292     pathBase.Copy( aPath );
       
  2293     if( pathBase.Length() > KPathDelim().Length() )
       
  2294         {
       
  2295         if( pathBase.Mid( pathBase.Length() -
       
  2296                           KPathDelim().Length()
       
  2297                          ).Compare( KPathDelim ) != 0 )
       
  2298             {
       
  2299             pathBase.Append( KPathDelim );
       
  2300             }
       
  2301         }
       
  2302             
       
  2303     TParsePtrC driveParser( pathBase );
       
  2304     TInt driveEnum = KErrNotFound;
       
  2305     
       
  2306     if( !aProcessOnlyDTD )
       
  2307         {
       
  2308         if( driveParser.DrivePresent() && driveParser.Drive().Length() > 0 )
       
  2309             {
       
  2310             User::LeaveIfError(
       
  2311                     RFs::CharToDrive( ( driveParser.Drive() )[0],
       
  2312                             driveEnum ) );
       
  2313             }
       
  2314         }
       
  2315     
       
  2316     _LIT( KFormatNN, "%02d" );    
       
  2317     TFileName localePath;
       
  2318     
       
  2319     for( TInt i = 0; i < languageCodes->Count(); i++ )
       
  2320         {                       
       
  2321         const TInt languageCode = languageCodes->At( i );
       
  2322 
       
  2323         // Construct locale path using two digit minium
       
  2324         // width and zero as padding.
       
  2325         
       
  2326         localePath.Copy( pathBase );
       
  2327         if( languageCode < 10 )
       
  2328             {
       
  2329             localePath.AppendFormat( KFormatNN, languageCode );
       
  2330             }
       
  2331         else
       
  2332             {
       
  2333             localePath.AppendNum( languageCode );
       
  2334             }
       
  2335         localePath.Append( KPathDelim );
       
  2336 
       
  2337         // Check if folder for supported language exists.        
       
  2338         TBool exists = EFalse;
       
  2339         
       
  2340         if( BaflUtils::FolderExists( iFsSession, localePath ) )
       
  2341             {
       
  2342             exists = ETrue;
       
  2343             }
       
  2344         
       
  2345         // Support also one digit type folder naming possibly used by the imports.
       
  2346         if( !exists && languageCode < 10 )
       
  2347             {
       
  2348             localePath.Copy( pathBase );
       
  2349             localePath.AppendNum( languageCode );        
       
  2350             localePath.Append( KPathDelim );
       
  2351             
       
  2352             if( BaflUtils::FolderExists( iFsSession, localePath ) )
       
  2353                 {
       
  2354                 exists = ETrue;
       
  2355                 }            
       
  2356             }
       
  2357 
       
  2358         if( exists )
       
  2359             {
       
  2360             // If we found the first language specification          
       
  2361             if ( !iDefaultSpecificationSet )
       
  2362                 {
       
  2363                 // Assume this is the default language shown incase 
       
  2364                 // there is no locale for the active UI language
       
  2365                 iDefaultSpecification = (TLanguage)languageCode;
       
  2366                 iDefaultSpecificationSet = ETrue;
       
  2367                 }                                                            
       
  2368                 
       
  2369             // Add dtd file if existing.
       
  2370             AddDtdFileL( localePath, (TLanguage)languageCode );
       
  2371             
       
  2372             if( !aProcessOnlyDTD )
       
  2373                 {
       
  2374                 // Find localized files from the provided directory
       
  2375                 RArray<TInt> driveArray;
       
  2376                 CleanupClosePushL( driveArray );                
       
  2377                 driveArray.Append( driveEnum );
       
  2378                 
       
  2379                 FindResourceFilesL( localePath,
       
  2380                                     EFalse,
       
  2381                                     driveArray,
       
  2382                                     NULL );
       
  2383                 
       
  2384                 CleanupStack::PopAndDestroy(); // driveArray
       
  2385                 }
       
  2386             }        
       
  2387         }
       
  2388     
       
  2389     CleanupStack::PopAndDestroy( languageCodes );
       
  2390     languageCodes = NULL;
       
  2391     }
       
  2392 
       
  2393 // -----------------------------------------------------------------------------
       
  2394 // Adds localized dtd resources from the provided subdirectory
       
  2395 // -----------------------------------------------------------------------------
       
  2396 //
       
  2397 void ChspsInstallationHandler::AddDtdFileL(
       
  2398         const TDesC& aPath,
       
  2399         const TLanguage aLanguage )
       
  2400     {    
       
  2401     // If FileDTD was declared
       
  2402     if ( iDtdFile && iDtdFile->Des().Length() )
       
  2403         {    
       
  2404         // Append path with the default name of DTD files
       
  2405         const TInt len = aPath.Length() + iDtdFile->Des().Length();
       
  2406         HBufC* dtdPath = HBufC::NewLC( len );
       
  2407         dtdPath->Des().Copy( aPath );    
       
  2408         dtdPath->Des().Append( *iDtdFile );
       
  2409             
       
  2410         // Check whether the file exists
       
  2411         if( !BaflUtils::FileExists( iFsSession, *dtdPath ) )
       
  2412             {
       
  2413 #ifdef HSPS_LOG_ACTIVE  
       
  2414             if( iLogBus )
       
  2415                 {
       
  2416                 iLogBus->LogText( _L( "ChspsInstallationHandler::AddLocalizedResourcesL(): - DTD file was not found '%S'" ),
       
  2417                         &dtdPath );
       
  2418                 }
       
  2419 #endif            
       
  2420             iFileNotFound = ETrue;
       
  2421             iResult->iXuikonError = KErrDtdFileNotFound;
       
  2422             User::Leave( KErrNotFound );
       
  2423             }           
       
  2424        
       
  2425         // Store locale specific DTD files into the resource array
       
  2426         TPtrC8 mediaType;
       
  2427         TPtrC8 tagsPtr;        
       
  2428         AddResourceL(
       
  2429             *iResourceList,
       
  2430             *dtdPath,
       
  2431             aLanguage,
       
  2432             EResourceDTD,
       
  2433             mediaType,
       
  2434             tagsPtr );
       
  2435         
       
  2436         CleanupStack::PopAndDestroy( dtdPath );
       
  2437         }          
       
  2438     }
       
  2439 
       
  2440 // -----------------------------------------------------------------------------
       
  2441 // ChspsInstallationHandler::ApplyUidRangeTestsL
       
  2442 // -----------------------------------------------------------------------------
       
  2443 //
       
  2444 void ChspsInstallationHandler::ApplyUidRangeTestsL( const TUint aUid )
       
  2445     {
       
  2446     // Check for TUint to TInt conversion
       
  2447     const TInt intValue( aUid );
       
  2448     if ( intValue < 1 )
       
  2449         {
       
  2450         // Check UID ranges in the manifest file
       
  2451 #ifdef HSPS_LOG_ACTIVE  
       
  2452         if( iLogBus )
       
  2453             {
       
  2454             iLogBus->LogText( _L( "ChspsInstallationHandler::ApplyUidRangeTestsL() - Invalid UID value '%d'" ), aUid );
       
  2455             }
       
  2456 #endif         
       
  2457         User::Leave( KErrArgument );
       
  2458         }
       
  2459     }
       
  2460 
       
  2461 
       
  2462 // -----------------------------------------------------------------------------
       
  2463 // ChspsInstallationHandler::ParseIconDeclarationL
       
  2464 // -----------------------------------------------------------------------------
       
  2465 //
       
  2466 void ChspsInstallationHandler::ParseIconDeclarationL(
       
  2467         HBufC8& aValue8,
       
  2468         const TDesC8& aTag,
       
  2469         HBufC*& aResultString )
       
  2470     {                
       
  2471     // 8bit > 16bit conversion
       
  2472     TInt size = KMaxFileName - iThemeFilePath.Length();
       
  2473     aResultString = HBufC::NewLC( KMaxFileName );
       
  2474     TPtr resultPtr( aResultString->Des() );    
       
  2475     resultPtr.Copy( aValue8.Des().Left( size ) );       
       
  2476     
       
  2477     // check whether skin/mif/uid declarations were used
       
  2478     TFileName filename;    
       
  2479     if ( hspsServerUtil::IsLogoFile( resultPtr, filename ) )
       
  2480         {                                                                              
       
  2481         // check whether the file reference is valid
       
  2482         TPath fullname;
       
  2483         fullname.Copy( iThemeFilePath );
       
  2484         fullname.Append( filename );      
       
  2485         
       
  2486         if( !BaflUtils::FileExists( iFsSession, fullname ) )
       
  2487             {
       
  2488 #ifdef HSPS_LOG_ACTIVE  
       
  2489             if( iLogBus )
       
  2490                 {
       
  2491                 iLogBus->LogText( 
       
  2492                         _L( "ChspsInstallationHandler::ParseIconDeclarationL(): - '%S' was not found " ), 
       
  2493                         &fullname );
       
  2494                 }
       
  2495 #endif               
       
  2496 //            User::Leave( KErrNotFound );
       
  2497             }
       
  2498         else
       
  2499             {                                           
       
  2500             // Store logo as a common resource file
       
  2501             TPtrC8 mediaType;                     
       
  2502             AddResourceL(
       
  2503                     *iResourceList,
       
  2504                     fullname,
       
  2505                     ELangNone,
       
  2506                     EResourceOther,
       
  2507                     mediaType,
       
  2508                     aTag );
       
  2509             
       
  2510             // get offset of the filename        
       
  2511             TInt nameOffset = resultPtr.FindF( (TPtrC)filename );
       
  2512             if ( nameOffset >= 0 )
       
  2513               {        
       
  2514               // get relative path under the HSPS 
       
  2515               if ( iRootUid < 1 || iProviderUid < 1 || iThemeUid < 1 || !iThemeVersion || iThemeVersion->Des().Length() < 1 )
       
  2516                   {
       
  2517                   User::Leave( KErrArgument );
       
  2518                   }  
       
  2519               // 8bit > 16bit
       
  2520               HBufC* verBuf = HBufC::NewLC( iThemeVersion->Des().Length() );
       
  2521               verBuf->Des().Copy( *iThemeVersion );            
       
  2522               _LIT(KPathFormat, "%D\\%D\\%D\\%S\\sources\\");                                 
       
  2523               TFileName relativePath;                      
       
  2524               relativePath.Format( 
       
  2525                       KPathFormat, 
       
  2526                       iRootUid,
       
  2527                       iProviderUid,
       
  2528                       iThemeUid,
       
  2529                       verBuf );                                
       
  2530               if ( resultPtr.Length() + relativePath.Length() > KMaxFileName - 1 )
       
  2531                   {
       
  2532                   User::Leave( KErrArgument );
       
  2533                   }                
       
  2534               resultPtr.Insert( nameOffset, relativePath );            
       
  2535               CleanupStack::PopAndDestroy( verBuf );            
       
  2536               }
       
  2537             
       
  2538             }       
       
  2539         
       
  2540         } // IsFile
       
  2541        
       
  2542     CleanupStack::Pop( aResultString );           
       
  2543     }
       
  2544 
       
  2545 // -----------------------------------------------------------------------------
       
  2546 // ChspsInstallationHandler::FindResourceFilesL
       
  2547 // -----------------------------------------------------------------------------
       
  2548 //
       
  2549 void ChspsInstallationHandler::FindResourceFilesL( const TDesC& aPath,
       
  2550         const TBool aRecursive,
       
  2551         RArray<TInt>& aDriveArray,
       
  2552         CArrayFixFlat<TInt>* aDeviceLanguages )
       
  2553     {
       
  2554     RPointerArray<HBufC> filesArray;    
       
  2555     CleanupResetAndDestroyPushL( filesArray );
       
  2556     
       
  2557     hspsServerUtil::FindResourcesL(
       
  2558             iFsSession,
       
  2559             aDriveArray,
       
  2560             aPath,
       
  2561             filesArray,
       
  2562             aDeviceLanguages,
       
  2563             aRecursive );    
       
  2564     
       
  2565     // Filter search results and select only relevant files
       
  2566     TInt error = KErrNone;
       
  2567     for( TInt i = 0; i < filesArray.Count(); i++ )
       
  2568         {            
       
  2569         const TFileName fileName = filesArray[ i ]->Des();
       
  2570         
       
  2571         // Check that file is listed in manifest resource.
       
  2572         
       
  2573         error = KErrNotFound;
       
  2574         
       
  2575         TParsePtrC fileNameParser( fileName );        
       
  2576         const TFileName fixedName =
       
  2577                 hspsServerUtil::GetFixedOdtName( fileNameParser.NameAndExt() );
       
  2578                 
       
  2579         ChspsResource* temporaryResource = NULL;
       
  2580         
       
  2581         for( TInt j = 0;
       
  2582                 j < iTempLocalizedResourceList->Count();
       
  2583                 j++ )
       
  2584             {        
       
  2585             temporaryResource = iTempLocalizedResourceList->At( j );
       
  2586             if( fixedName.CompareF( temporaryResource->FileName() ) == 0  )
       
  2587                 {
       
  2588                 error = KErrNone;
       
  2589                 break;
       
  2590                 }
       
  2591             }
       
  2592 
       
  2593         // Extract localisation code from path.
       
  2594         
       
  2595         TInt localizationCode = 0;
       
  2596         
       
  2597         if( error == KErrNone )
       
  2598             {                        
       
  2599             TPath path = fileNameParser.Path();                
       
  2600             if( path.Right( KPathDelim().Length() ).Compare( KPathDelim() ) == 0 )
       
  2601                 {
       
  2602                 path.Delete( path.Length() - KPathDelim().Length(), KPathDelim().Length() );
       
  2603                 }
       
  2604     
       
  2605             TParsePtrC localizationParser( path );
       
  2606             TLex lex( localizationParser.Name() );        
       
  2607             error = lex.Val( localizationCode );
       
  2608             
       
  2609             if( error == KErrNone && localizationCode < ELangTest )
       
  2610                 {
       
  2611                 error = KErrCorrupt;
       
  2612                 }
       
  2613             }
       
  2614         
       
  2615         // Check for duplicates.
       
  2616         
       
  2617         if( error == KErrNone )
       
  2618             {
       
  2619             for( TInt k = 0; k < iResourceList->Count(); k++ )
       
  2620                 {
       
  2621                 ChspsResource* resource = iResourceList->At( k );
       
  2622                 
       
  2623                 if( resource->Language() == localizationCode &&
       
  2624                     resource->FileName().CompareF( fileName ) == 0 )
       
  2625                     {
       
  2626                     error = KErrAlreadyExists;
       
  2627                     break;
       
  2628                     }
       
  2629                 }
       
  2630             }
       
  2631         
       
  2632         // Add to actual resource list. 
       
  2633         if( error == KErrNone )
       
  2634             {
       
  2635             TPtrC8 tag;                                                               
       
  2636             HBufC8* tagBuf8 = NULL;                        
       
  2637             
       
  2638             if ( temporaryResource->Tags().Length() )
       
  2639                 {
       
  2640                 tagBuf8 = HBufC8::NewLC( temporaryResource->Tags().Length() );
       
  2641                 tagBuf8->Des().Copy( temporaryResource->Tags() );
       
  2642                 tag.Set( tagBuf8->Des() );
       
  2643                 }
       
  2644                         
       
  2645             TDataType dataType( temporaryResource->MimeType() );            
       
  2646             
       
  2647             // Add localized files into the resource array                    
       
  2648             AddResourceL(
       
  2649                     *iResourceList,
       
  2650                     fileName,
       
  2651                     (TLanguage)localizationCode,
       
  2652                     EResourceOther,
       
  2653                     dataType.Des8(),
       
  2654                     tag );
       
  2655             
       
  2656             if ( tagBuf8 )
       
  2657                 {
       
  2658                 CleanupStack::PopAndDestroy( tagBuf8 );
       
  2659                 }
       
  2660             }
       
  2661         }
       
  2662 
       
  2663     CleanupStack::PopAndDestroy(); // filesArray
       
  2664     }
       
  2665 
       
  2666 // end of file