|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // DBMS - security policy file tool |
|
15 // |
|
16 // |
|
17 |
|
18 #include <s32file.h> |
|
19 #include "cn_main.h" |
|
20 #include "cn_bin2txt.h" |
|
21 #include "cn_util.h" |
|
22 #include "SC_StrmIn.h" |
|
23 #include "SC_TextOut.h" |
|
24 |
|
25 using namespace DBSC; |
|
26 |
|
27 /** |
|
28 CSPBin2Txt::RunL() implements pure virtual CCmdProcessor::RunL(). |
|
29 It opens the input binary policy file and creates in-memory presentation of the |
|
30 policies found there. Then it stores the policies in a text file (in human readable format). |
|
31 CSPBin2Txt::RunL() uses TPDStreamLoader class to load policies for the binary file |
|
32 and CPDTextPersister class to store them in a text file. |
|
33 @leave System-wide error codes in case of failure |
|
34 @see CCmdProcessor::RunL() |
|
35 @see TPDStreamLoader |
|
36 @see CPDTextPersister |
|
37 */ |
|
38 void CSPBin2Txt::RunL() |
|
39 { |
|
40 RFileReadStream streamIn; |
|
41 CleanupClosePushL(streamIn); |
|
42 __LEAVE_IF_ERROR(streamIn.Open(iFs, iCmdLinePrm.iBinFile, EFileRead)); |
|
43 |
|
44 TPDStreamLoader streamLoader(streamIn); |
|
45 |
|
46 TUid domainUid = TSPConvUtil::UidFromFileNameL(iCmdLinePrm.iBinFile); |
|
47 |
|
48 CPolicyDomain* policyDomain = CPolicyDomain::NewLC(domainUid, streamLoader); |
|
49 |
|
50 CPDTextPersister* textPersister = CPDTextPersister::NewLC(iFs, iCmdLinePrm.iTxtFile); |
|
51 policyDomain->ExternalizeL(*textPersister); |
|
52 CleanupStack::PopAndDestroy(textPersister); |
|
53 |
|
54 CleanupStack::PopAndDestroy(policyDomain); |
|
55 CleanupStack::PopAndDestroy(&streamIn); |
|
56 } |
|
57 |
|
58 /** |
|
59 */ |
|
60 CSPBin2Txt::~CSPBin2Txt() |
|
61 { |
|
62 } |
|
63 |
|
64 /** |
|
65 */ |
|
66 inline CSPBin2Txt::CSPBin2Txt(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) : |
|
67 CCmdProcessor(aFs, aCmdLinePrm) |
|
68 { |
|
69 } |
|
70 |
|
71 /** |
|
72 Standard phase-one CSPBin2Txt factory method. |
|
73 @param aFs File server session |
|
74 @param aCmdLinePrm Parsed command line arguments: requested action, input and output file paths |
|
75 @return A pointer to successfully created CSPBin2Txt instance. |
|
76 @leave KErrNoMemory - not enough memory |
|
77 @leave KErrNotFound - input file not found |
|
78 @leave KErrAlreadyExists - output file already exists |
|
79 */ |
|
80 CSPBin2Txt* CSPBin2Txt::NewLC(RFs& aFs, const TCmdLinePrm& aCmdLinePrm) |
|
81 { |
|
82 __ASSERT(aCmdLinePrm.iAction == TCmdLinePrm::EBin2Txt); |
|
83 CSPBin2Txt* self = new (ELeave) CSPBin2Txt(aFs, aCmdLinePrm); |
|
84 CleanupStack::PushL(self); |
|
85 self->ConstructL(); |
|
86 return self; |
|
87 } |
|
88 |
|
89 /** |
|
90 Standard phase-two CSPBin2Txt construction method. |
|
91 */ |
|
92 void CSPBin2Txt::ConstructL() |
|
93 { |
|
94 __ASSERT(iCmdLinePrm.iTxtFile.Length() > 0); |
|
95 __ASSERT(iCmdLinePrm.iBinFile.Length() > 0); |
|
96 if(!TSPConvUtil::FileExists(iFs, iCmdLinePrm.iBinFile)) |
|
97 { |
|
98 _LIT(KText, "\"UID\" file \"%S\" not found\n"); |
|
99 TSPConvUtil::Print(KText, iCmdLinePrm.iBinFile); |
|
100 __LEAVE(KErrNotFound); |
|
101 } |
|
102 if(TSPConvUtil::FileExists(iFs, iCmdLinePrm.iTxtFile)) |
|
103 { |
|
104 _LIT(KText, "File \"%S\" already exists!\n"); |
|
105 TSPConvUtil::Print(KText, iCmdLinePrm.iTxtFile); |
|
106 __LEAVE(KErrAlreadyExists); |
|
107 } |
|
108 } |