|
1 /* |
|
2 * Copyright (c) 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 "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 #include "trustrootpolicy.h" |
|
18 |
|
19 _LIT8(KXmlMimeType, "text/xml"); |
|
20 |
|
21 // tag names |
|
22 _LIT8(KTrustRoot, "trustroot"); |
|
23 _LIT8(KName, "name"); |
|
24 _LIT8(KDomain, "domain"); |
|
25 _LIT8(KMcc, "mcc"); |
|
26 _LIT8(KMnc, "mnc"); |
|
27 _LIT8(KDisable, "disable"); |
|
28 _LIT8(KDelete, "delete"); |
|
29 |
|
30 CTrustRootPolicy* CTrustRootPolicy::NewL() |
|
31 { |
|
32 CTrustRootPolicy* self = new(ELeave) CTrustRootPolicy(); |
|
33 CleanupStack::PushL(self); |
|
34 self->ConstructL(); |
|
35 CleanupStack::Pop(self); |
|
36 return self; |
|
37 } |
|
38 |
|
39 CTrustRootPolicy::~CTrustRootPolicy() |
|
40 { |
|
41 iRfs.Close(); |
|
42 if (iParser) |
|
43 { |
|
44 delete iParser; |
|
45 iParser = NULL; |
|
46 } |
|
47 } |
|
48 |
|
49 CTrustRootPolicy::CTrustRootPolicy() |
|
50 { |
|
51 } |
|
52 |
|
53 void CTrustRootPolicy::ConstructL() |
|
54 { |
|
55 User::LeaveIfError(iRfs.Connect()); |
|
56 iParser = CParser::NewL(KXmlMimeType, *this); |
|
57 } |
|
58 |
|
59 void CTrustRootPolicy::ReadFromFileL(const TDesC& aPolicyFileName, vector<TrustRoot>& aTrustRoots) |
|
60 { |
|
61 |
|
62 RFile file; |
|
63 TInt size; |
|
64 User::LeaveIfError(file.Open(iRfs, aPolicyFileName, EFileRead)); |
|
65 User::LeaveIfError(file.Size(size)); |
|
66 |
|
67 HBufC8* buffer = HBufC8::NewLC(size); |
|
68 TPtr8 bufferPtr(buffer->Des()); |
|
69 User::LeaveIfError(file.Read(bufferPtr)); |
|
70 |
|
71 iTrustRoots = &aTrustRoots; |
|
72 iParser->ParseBeginL(); |
|
73 iParser->ParseL(*buffer); |
|
74 iParser->ParseEndL(); |
|
75 |
|
76 CleanupStack::PopAndDestroy(); // buffer |
|
77 } |
|
78 |
|
79 void CTrustRootPolicy::OnStartDocumentL(const RDocumentParameters& /*aDocParam*/, TInt /*aErrorCode*/) |
|
80 { |
|
81 } |
|
82 |
|
83 void CTrustRootPolicy::OnEndDocumentL(TInt /*aErrorCode*/) |
|
84 { |
|
85 } |
|
86 |
|
87 void CTrustRootPolicy::OnStartElementL(const RTagInfo& aElement, const RAttributeArray& /*aAttributes*/, TInt /*aErrorCode*/) |
|
88 { |
|
89 iCurrentContent.clear(); |
|
90 const TDesC8& tagName = aElement.LocalName().DesC(); |
|
91 if (tagName.Compare(KTrustRoot) == 0) |
|
92 { |
|
93 iTrustRoot = TrustRoot(); |
|
94 } |
|
95 } |
|
96 |
|
97 void CTrustRootPolicy::OnEndElementL(const RTagInfo& aElement, TInt /*aErrorCode*/) |
|
98 { |
|
99 const TDesC8& tagName = aElement.LocalName().DesC(); |
|
100 if (tagName.Compare(KTrustRoot) == 0) |
|
101 { |
|
102 iTrustRoots->push_back(iTrustRoot); |
|
103 } |
|
104 else if (tagName.Compare(KName) == 0) |
|
105 { |
|
106 iTrustRoot.iName = iCurrentContent; |
|
107 } |
|
108 else if (tagName.Compare(KDomain) == 0) |
|
109 { |
|
110 iTrustRoot.iDomain = iCurrentContent; |
|
111 } |
|
112 else if (tagName.Compare(KMcc) == 0) |
|
113 { |
|
114 iTrustRoot.iMcc = iCurrentContent; |
|
115 } |
|
116 else if (tagName.Compare(KMnc) == 0) |
|
117 { |
|
118 iTrustRoot.iMnc = iCurrentContent; |
|
119 } |
|
120 else if (tagName.Compare(KDisable) == 0) |
|
121 { |
|
122 iTrustRoot.iCanDisable = true; |
|
123 } |
|
124 else if (tagName.Compare(KDelete) == 0) |
|
125 { |
|
126 iTrustRoot.iCanDelete = true; |
|
127 } |
|
128 } |
|
129 |
|
130 void CTrustRootPolicy::OnContentL(const TDesC8& aBytes, TInt /*aErrorCode*/) |
|
131 { |
|
132 // append aBytes to iCurrentContent |
|
133 iCurrentContent.append((const char*)aBytes.Ptr(), aBytes.Length()); |
|
134 } |
|
135 |
|
136 void CTrustRootPolicy::OnStartPrefixMappingL(const RString& /*aPrefix*/, const RString& /*aUri*/, TInt /*aErrorCode*/) |
|
137 { |
|
138 } |
|
139 |
|
140 void CTrustRootPolicy::OnEndPrefixMappingL(const RString& /*aPrefix*/, TInt /*aErrorCode*/) |
|
141 { |
|
142 } |
|
143 |
|
144 void CTrustRootPolicy::OnIgnorableWhiteSpaceL(const TDesC8& /*aBytes*/,TInt /*aErrorCode*/) |
|
145 { |
|
146 } |
|
147 |
|
148 void CTrustRootPolicy::OnSkippedEntityL(const RString& /*aName*/,TInt /*aErrorCode*/) |
|
149 { |
|
150 } |
|
151 void CTrustRootPolicy::OnProcessingInstructionL(const TDesC8& /*aTarget*/, const TDesC8& /*aData*/, TInt /*aErrorCode*/) |
|
152 { |
|
153 } |
|
154 |
|
155 void CTrustRootPolicy::OnError(TInt /*aErrorCode*/) |
|
156 { |
|
157 } |
|
158 |
|
159 TAny* CTrustRootPolicy::GetExtendedInterface(const TInt32 /*aUid*/) |
|
160 { |
|
161 return 0; |
|
162 } |
|
163 |
|
164 TrustRoot::TrustRoot() |
|
165 { |
|
166 iName = ""; |
|
167 iDomain = ""; |
|
168 iMcc = ""; |
|
169 iMnc = ""; |
|
170 iCanDelete = false; |
|
171 iCanDisable = false; |
|
172 } |