installationservices/swi/source/swis/server/installswtypehelper.cpp
changeset 0 ba25891c3a9e
child 25 7333d7932ef7
equal deleted inserted replaced
-1:000000000000 0:ba25891c3a9e
       
     1 /*
       
     2 * Copyright (c) 2008-2009 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 the License "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: 
       
    15 * installswtypehelper.h
       
    16 *
       
    17 */
       
    18 
       
    19 
       
    20 #include <f32file.h>
       
    21 #include <ct/rcpointerarray.h>
       
    22 #include <swi/sisinstallerrors.h>
       
    23 #include <usif/usifcommon.h>
       
    24 #include "installswtypehelper.h"
       
    25 #include "swtypereginfo.h"
       
    26 #include "sislauncherclient.h"
       
    27 #include "log.h"
       
    28 
       
    29 namespace Swi
       
    30 	{
       
    31 	namespace InstallSoftwareTypeHelper
       
    32 		{
       
    33 		_LIT(KSwTypeRegDir, "\\resource\\usif\\leestore\\");
       
    34 		_LIT(KSwTypeRegFileExt, ".xml");
       
    35 		const TInt KSwTypeRegFileMaxSize = 0x3FFF; // 16kB
       
    36 
       
    37 		TBool IsValidSwRegFileL(const TDesC& aFileName, TInt32 aAppUid)
       
    38 			{
       
    39 			// Check file path and extension
       
    40 			TParsePtrC filename(aFileName);
       
    41 			if (filename.Path().CompareF(KSwTypeRegDir) || filename.Ext().CompareF(KSwTypeRegFileExt))
       
    42 				{
       
    43 				return EFalse;
       
    44 				}
       
    45 			
       
    46 			// Check file name
       
    47 			TLex lex(filename.Name());
       
    48 			TUint32 uid(0);
       
    49 			TInt err = lex.Val(uid, EHex);
       
    50 			if (err != KErrNone)
       
    51 				{
       
    52 				DEBUG_PRINTF3(_L8("Failed to convert file name %S to UID, err = %d\n"), &aFileName, err);
       
    53 				User::Leave(KErrInvalidSoftwareTypeRegistrationFile);
       
    54 				}
       
    55 			if (uid != static_cast<TUint32>(aAppUid))
       
    56 				{
       
    57 				DEBUG_PRINTF3(_L8("Registration file name %S doesn't match package UID %d\n"), &aFileName, uid);
       
    58 				User::Leave(KErrInvalidSoftwareTypeRegistrationFile);
       
    59 				}
       
    60 			
       
    61 			return ETrue;
       
    62 			}
       
    63 
       
    64 		void ParseRegFileL(RFs& aFs, const TDesC& aFileName, RPointerArray<CSoftwareTypeRegInfo>& aInfoArray)
       
    65 			{
       
    66 			// Open the file for reading
       
    67 			RFile file;
       
    68 			TInt err = file.Open(aFs, aFileName, EFileShareReadersOnly);
       
    69 			if (err != KErrNone)
       
    70 				{
       
    71 				DEBUG_PRINTF3(_L("Failed to open the file %S for reading, err = %d\n"), &aFileName, err);
       
    72 				User::Leave(err);
       
    73 				}
       
    74 			CleanupClosePushL(file);
       
    75 
       
    76 			// Check the size of the registration file
       
    77 			TInt size = 0;
       
    78 			err = file.Size(size);
       
    79 			if (err != KErrNone)
       
    80 				{
       
    81 				DEBUG_PRINTF3(_L("Failed to get the size of the file %S for reading, err = %d\n"), &aFileName, err);
       
    82 				User::Leave(err);
       
    83 				}
       
    84 			if (size > KSwTypeRegFileMaxSize)
       
    85 				{
       
    86 				DEBUG_PRINTF3(_L8("Software type registration file is too big. Current size: %d, max size: %d\n"), size, KSwTypeRegFileMaxSize);
       
    87 				User::Leave(KErrInvalidSoftwareTypeRegistrationFile);
       
    88 				}
       
    89 
       
    90 			// Use SISLauncher to parse the xml registration file
       
    91 			RSisLauncherSession launcher;
       
    92 			CleanupClosePushL(launcher);
       
    93 			err = launcher.Connect();
       
    94 			if (err != KErrNone)
       
    95 				{
       
    96 				DEBUG_PRINTF2(_L8("Failed to connect to the SISLauncher, err = %d\n"), err);
       
    97 				User::Leave(err);
       
    98 				}
       
    99 			launcher.ParseSwTypeRegFileL(file, aInfoArray);
       
   100 			
       
   101 			// Verify that the native type is not claimed - this would be a security violation
       
   102 			for (TInt i = 0; i < aInfoArray.Count(); ++i)
       
   103 				{
       
   104 				const TDesC& uniqueTypeName = aInfoArray[i]->UniqueSoftwareTypeName();
       
   105 				if (uniqueTypeName == Usif::KSoftwareTypeNative)
       
   106 					{
       
   107 					DEBUG_PRINTF(_L8("Software type registration file attempts changing the registation for the native installer\n"));
       
   108 					User::Leave(KErrSecurityError);
       
   109 					}
       
   110 				}			
       
   111 
       
   112 			CleanupStack::PopAndDestroy(2, &file); // launcher
       
   113 			}
       
   114 
       
   115 		void RegisterMimeTypesL(const RPointerArray<CSoftwareTypeRegInfo>& aInfoArray)
       
   116 			{
       
   117 			const TInt numElems = aInfoArray.Count();
       
   118 			if (numElems == 0)
       
   119 				{
       
   120 				return;
       
   121 				}
       
   122 
       
   123 			// Create a list of MIME types
       
   124 			RCPointerArray<HBufC8> mimeTypes;
       
   125 			CleanupClosePushL(mimeTypes);
       
   126 			SoftwareTypeRegInfoUtils::ExtractMimeTypesL(aInfoArray, mimeTypes);
       
   127 
       
   128 			// Use SISLauncher to register MIME types for SIFLauncher
       
   129 			RSisLauncherSession launcher;
       
   130 			CleanupClosePushL(launcher);
       
   131 			TInt err = launcher.Connect();
       
   132 			if (err != KErrNone)
       
   133 				{
       
   134 				DEBUG_PRINTF2(_L8("Failed to connect to the SISLauncher, err = %d\n"), err);
       
   135 				User::Leave(err);
       
   136 				}
       
   137 			launcher.RegisterSifLauncherMimeTypesL(mimeTypes);
       
   138 
       
   139 			CleanupStack::PopAndDestroy(2, &mimeTypes); // launcher
       
   140 			}
       
   141 		} // namespace InstallSoftwareTypeHelper
       
   142 	} // namespace Swi