os/security/cryptoservices/filebasedcertificateandkeystores/source/generic/server/fstokenutil.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     1 /*
     2 * Copyright (c) 2003-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 *
    16 */
    17 
    18 
    19 #include "fstokenutil.h"
    20 #include <f32file.h>
    21 #include <s32file.h>
    22 
    23 // RMessage::Panic() also completes the message. This is:
    24 // (a) important for efficient cleanup within the kernel
    25 // (b) a problem if the message is completed a second time
    26 void PanicClient(const RMessage2& aMessage, ETokenTypeServerPanic aPanic)
    27 	{
    28 	_LIT(KPanicClient,"TTSERVERCLIENT");
    29 	aMessage.Panic(KPanicClient,aPanic);
    30 	}
    31 
    32 void PanicServer(ETokenTypeServerPanic aPanicCode)
    33 	{
    34 	_LIT(KPanicServer,"TOKENTYPESERVER");
    35 	User::Panic(KPanicServer, aPanicCode);
    36 	}
    37 
    38 /// Rom drive where the initial store data is
    39 _LIT(KFileStoreROMDrive, "Z:");
    40 
    41 TBool FileUtils::ExistsL(RFs& aFs, const TDesC& aFile)
    42 	{
    43 	TBool result = EFalse;
    44 	TBool open;
    45 	TInt err = aFs.IsFileOpen(aFile, open);
    46 	
    47 	if (err == KErrNone)
    48 		{
    49 		result = ETrue;
    50 		}
    51 	else if (err != KErrNotFound && err != KErrPathNotFound)
    52 		{
    53 		User::Leave(err);
    54 		}
    55 
    56 	return result;
    57 	}
    58 
    59 void FileUtils::EnsurePathL(RFs& aFs, const TDesC& aFile)
    60 	{
    61 	TInt err = aFs.MkDirAll(aFile);
    62 	if (err != KErrNone && err != KErrAlreadyExists)
    63 		{
    64 		User::Leave(err);
    65 		}
    66 	}
    67 
    68 void FileUtils::CopyL(RFs& aFs, const TDesC& aSouce, const TDesC& aDest)
    69 	{
    70 	RFileReadStream in;
    71 	User::LeaveIfError(in.Open(aFs, aSouce, EFileRead | EFileShareReadersOnly));
    72 	CleanupClosePushL(in);
    73 
    74 	RFileWriteStream out;
    75 	User::LeaveIfError(out.Replace(aFs, aDest, EFileWrite | EFileShareExclusive));
    76 	CleanupClosePushL(out);
    77 
    78 	in.ReadL(out);	
    79 	CleanupStack::PopAndDestroy(2, &in);
    80 	}
    81 
    82 void FileUtils::MakePrivateFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut)
    83 	{
    84 	aNameOut.SetLength(0);	
    85 	aNameOut.Append(RFs::GetSystemDriveChar());
    86 
    87 	aNameOut.Append(':');
    88 
    89 	// Get private path
    90 	TBuf<20> privatePath;
    91 	aFs.PrivatePath(privatePath);
    92 	aNameOut.Append(privatePath);
    93 	
    94 	aNameOut.Append(aLeafName);
    95 	}
    96 
    97 void FileUtils::MakePrivateROMFilenameL(RFs& aFs, const TDesC& aLeafName, TDes& aNameOut)
    98 	{
    99 	aNameOut.Copy(KFileStoreROMDrive);
   100 
   101 	// Get private path
   102 	TBuf<20> privatePath;
   103 	aFs.PrivatePath(privatePath);
   104 	aNameOut.Append(privatePath);
   105 	
   106 	aNameOut.Append(aLeafName);
   107 	}