os/persistentdata/persistentstorage/dbms/SPConv/cn_bin2txt.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/persistentdata/persistentstorage/dbms/SPConv/cn_bin2txt.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,108 @@
     1.4 +// Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// DBMS - security policy file tool
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include <s32file.h>
    1.22 +#include "cn_main.h"
    1.23 +#include "cn_bin2txt.h"
    1.24 +#include "cn_util.h"
    1.25 +#include "SC_StrmIn.h"
    1.26 +#include "SC_TextOut.h"
    1.27 +
    1.28 +using namespace DBSC;
    1.29 +
    1.30 +/**
    1.31 +CSPBin2Txt::RunL() implements pure virtual CCmdProcessor::RunL().
    1.32 +It opens the input binary policy file and creates in-memory presentation of the 
    1.33 +policies found there. Then it stores the policies in a text file (in human readable format).
    1.34 +CSPBin2Txt::RunL() uses TPDStreamLoader class to load policies for the binary file
    1.35 +and CPDTextPersister class to store them in a text file.
    1.36 +@leave System-wide error codes in case of failure
    1.37 +@see CCmdProcessor::RunL()
    1.38 +@see TPDStreamLoader
    1.39 +@see CPDTextPersister
    1.40 +*/
    1.41 +void CSPBin2Txt::RunL()
    1.42 +	{
    1.43 +	RFileReadStream streamIn;
    1.44 +	CleanupClosePushL(streamIn);
    1.45 +	__LEAVE_IF_ERROR(streamIn.Open(iFs, iCmdLinePrm.iBinFile, EFileRead));
    1.46 +
    1.47 +	TPDStreamLoader streamLoader(streamIn);
    1.48 +
    1.49 +	TUid domainUid = TSPConvUtil::UidFromFileNameL(iCmdLinePrm.iBinFile);
    1.50 +
    1.51 +	CPolicyDomain* policyDomain = CPolicyDomain::NewLC(domainUid, streamLoader);
    1.52 +
    1.53 +	CPDTextPersister* textPersister = CPDTextPersister::NewLC(iFs, iCmdLinePrm.iTxtFile);
    1.54 +	policyDomain->ExternalizeL(*textPersister);
    1.55 +	CleanupStack::PopAndDestroy(textPersister);
    1.56 +
    1.57 +	CleanupStack::PopAndDestroy(policyDomain);
    1.58 +	CleanupStack::PopAndDestroy(&streamIn);
    1.59 +	}
    1.60 +
    1.61 +/**
    1.62 +*/
    1.63 +CSPBin2Txt::~CSPBin2Txt()
    1.64 +	{
    1.65 +	}
    1.66 +
    1.67 +/**
    1.68 +*/
    1.69 +inline CSPBin2Txt::CSPBin2Txt(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) :
    1.70 +	CCmdProcessor(aFs, aCmdLinePrm)
    1.71 +	{
    1.72 +	}
    1.73 +
    1.74 +/**
    1.75 +Standard phase-one CSPBin2Txt factory method.
    1.76 +@param aFs File server session
    1.77 +@param aCmdLinePrm Parsed command line arguments: requested action, input and output file paths
    1.78 +@return A pointer to successfully created CSPBin2Txt instance.
    1.79 +@leave KErrNoMemory - not enough memory
    1.80 +@leave KErrNotFound - input file not found
    1.81 +@leave KErrAlreadyExists - output file already exists
    1.82 +*/
    1.83 +CSPBin2Txt* CSPBin2Txt::NewLC(RFs& aFs, const TCmdLinePrm& aCmdLinePrm)
    1.84 +	{
    1.85 +	__ASSERT(aCmdLinePrm.iAction == TCmdLinePrm::EBin2Txt);
    1.86 +	CSPBin2Txt* self = new (ELeave) CSPBin2Txt(aFs, aCmdLinePrm);
    1.87 +	CleanupStack::PushL(self);
    1.88 +	self->ConstructL();
    1.89 +	return self;
    1.90 +	}
    1.91 +
    1.92 +/**
    1.93 +Standard phase-two CSPBin2Txt construction method.
    1.94 +*/
    1.95 +void CSPBin2Txt::ConstructL()
    1.96 +	{
    1.97 +	__ASSERT(iCmdLinePrm.iTxtFile.Length() > 0);
    1.98 +	__ASSERT(iCmdLinePrm.iBinFile.Length() > 0);
    1.99 +	if(!TSPConvUtil::FileExists(iFs, iCmdLinePrm.iBinFile))
   1.100 +		{
   1.101 +		_LIT(KText, "\"UID\" file \"%S\" not found\n");
   1.102 +		TSPConvUtil::Print(KText, iCmdLinePrm.iBinFile);
   1.103 +		__LEAVE(KErrNotFound);
   1.104 +		}
   1.105 +	if(TSPConvUtil::FileExists(iFs, iCmdLinePrm.iTxtFile))
   1.106 +		{
   1.107 +		_LIT(KText, "File \"%S\" already exists!\n");
   1.108 +		TSPConvUtil::Print(KText, iCmdLinePrm.iTxtFile);
   1.109 +		__LEAVE(KErrAlreadyExists);
   1.110 +		}
   1.111 +	}