|
1 /* |
|
2 * Copyright (c) 2004-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: Handler class for Trust Settings Store calls from WimClient |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "WimTrustSettingsHandler.h" |
|
22 #include "WimTrustSettingsStore.h" |
|
23 #include "WimClsv.h" |
|
24 #include "WimCertInfo.h" |
|
25 #include "WimTrace.h" |
|
26 |
|
27 #ifdef _DEBUG |
|
28 _LIT( KWimTrustSettPanic, "WimTrustSett" ); |
|
29 #endif |
|
30 |
|
31 // ============================ MEMBER FUNCTIONS =============================== |
|
32 |
|
33 // ----------------------------------------------------------------------------- |
|
34 // CWimTrustSettingsHandler::CWimTrustSettingsHandler |
|
35 // C++ default constructor can NOT contain any code, that |
|
36 // might leave. |
|
37 // ----------------------------------------------------------------------------- |
|
38 // |
|
39 CWimTrustSettingsHandler::CWimTrustSettingsHandler( |
|
40 CWimTrustSettingsStore* aWimTrustSettingsStore ) |
|
41 : CActive( EPriorityStandard ), |
|
42 iWimTrustSettingsStore( aWimTrustSettingsStore ) |
|
43 { |
|
44 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::CWimTrustSettingsHandler | Begin")); |
|
45 } |
|
46 |
|
47 // ----------------------------------------------------------------------------- |
|
48 // CWimTrustSettingsHandler::ConstructL |
|
49 // Symbian 2nd phase constructor can leave. |
|
50 // ----------------------------------------------------------------------------- |
|
51 // |
|
52 void CWimTrustSettingsHandler::ConstructL() |
|
53 { |
|
54 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::ConstructL | Begin")); |
|
55 CActiveScheduler::Add( this ); |
|
56 } |
|
57 |
|
58 // ----------------------------------------------------------------------------- |
|
59 // CWimTrustSettingsHandler::NewL |
|
60 // Two-phased constructor. |
|
61 // ----------------------------------------------------------------------------- |
|
62 // |
|
63 CWimTrustSettingsHandler* CWimTrustSettingsHandler::NewL( |
|
64 CWimTrustSettingsStore* aWimTrustSettingsStore ) |
|
65 { |
|
66 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::NewL | Begin")); |
|
67 CWimTrustSettingsHandler* self = new( ELeave ) CWimTrustSettingsHandler( |
|
68 aWimTrustSettingsStore ); |
|
69 |
|
70 CleanupStack::PushL( self ); |
|
71 self->ConstructL(); |
|
72 CleanupStack::Pop( self ); |
|
73 |
|
74 return self; |
|
75 } |
|
76 |
|
77 |
|
78 // Destructor |
|
79 CWimTrustSettingsHandler::~CWimTrustSettingsHandler() |
|
80 { |
|
81 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::~CWimTrustSettingsHandler | Begin")); |
|
82 iApplications.Close(); |
|
83 delete iCertInfo; |
|
84 iWimTrustSettingsStore = NULL; // not owned |
|
85 } |
|
86 |
|
87 // ----------------------------------------------------------------------------- |
|
88 // CWimTrustSettingsHandler::GetTrustSettingsL |
|
89 // Fetches trust settings for given certificate. |
|
90 // ----------------------------------------------------------------------------- |
|
91 // |
|
92 void CWimTrustSettingsHandler::GetTrustSettingsL( const RMessage2& aMessage ) |
|
93 { |
|
94 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::GetTrustSettingsL | Begin")); |
|
95 |
|
96 TPckgBuf<TWimCertInfoPckg> pckg; |
|
97 |
|
98 aMessage.ReadL( 0, pckg ); |
|
99 |
|
100 __ASSERT_DEBUG( iCertInfo == NULL, User::Panic( KWimTrustSettPanic, KErrGeneral ) ); |
|
101 iCertInfo = CWimCertInfo::InternalizeL( pckg() ); |
|
102 |
|
103 iStatus = KRequestPending; |
|
104 iMessage = aMessage; |
|
105 iPhase = EGetTrustSettings; |
|
106 SetActive(); |
|
107 iWimTrustSettingsStore->GetTrustSettings( *iCertInfo, |
|
108 iTrusted, |
|
109 iApplications, |
|
110 iStatus ); |
|
111 } |
|
112 |
|
113 // ----------------------------------------------------------------------------- |
|
114 // CWimTrustSettingsHandler::SetApplicabilityL |
|
115 // Set applicability for given certificate. New certificate entry is set if |
|
116 // one not found from database (trust flag is set to EFalse). |
|
117 // ----------------------------------------------------------------------------- |
|
118 // |
|
119 void CWimTrustSettingsHandler::SetApplicabilityL( const RMessage2& aMessage ) |
|
120 { |
|
121 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::SetApplicabilityL | Begin")); |
|
122 |
|
123 TPckgBuf<TWimCertInfoPckg> pckg; |
|
124 aMessage.ReadL( 0, pckg ); |
|
125 |
|
126 __ASSERT_DEBUG( iCertInfo == NULL, User::Panic( KWimTrustSettPanic, KErrGeneral ) ); |
|
127 iCertInfo = CWimCertInfo::InternalizeL( pckg() ); |
|
128 |
|
129 RArray<TUid> applications; |
|
130 CleanupClosePushL( applications ); |
|
131 |
|
132 TPckgBuf<TTrustSettings> trustSettingsPckg; |
|
133 |
|
134 aMessage.ReadL( 1, trustSettingsPckg ); |
|
135 |
|
136 TInt applicationCount = trustSettingsPckg().iApplicationCount; |
|
137 |
|
138 for ( TInt i = 0; i < applicationCount; i++ ) |
|
139 { |
|
140 TUid uid; |
|
141 uid.iUid = trustSettingsPckg().iUids[i]; |
|
142 applications.Append( uid ); |
|
143 } |
|
144 |
|
145 iStatus = KRequestPending; |
|
146 iMessage = aMessage; |
|
147 iPhase = ESetApplicability; |
|
148 SetActive(); |
|
149 iWimTrustSettingsStore->SetApplicability( *iCertInfo, |
|
150 applications, |
|
151 iStatus ); |
|
152 |
|
153 CleanupStack::PopAndDestroy( &applications ); |
|
154 } |
|
155 |
|
156 // ----------------------------------------------------------------------------- |
|
157 // CWimTrustSettingsHandler::SetTrustL |
|
158 // Set trust flag for given certificate. New certificate entry is set if |
|
159 // one not found from database. |
|
160 // ----------------------------------------------------------------------------- |
|
161 // |
|
162 void CWimTrustSettingsHandler::SetTrustL( const RMessage2& aMessage ) |
|
163 { |
|
164 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::SetTrustL | Begin")); |
|
165 |
|
166 TPckgBuf<TWimCertInfoPckg> pckg; |
|
167 aMessage.ReadL( 0, pckg ); |
|
168 |
|
169 __ASSERT_DEBUG( iCertInfo == NULL, User::Panic( KWimTrustSettPanic, KErrGeneral ) ); |
|
170 iCertInfo = CWimCertInfo::InternalizeL( pckg() ); |
|
171 |
|
172 TPckgBuf<TTrustSettings> trustSettingsPckg; |
|
173 |
|
174 aMessage.ReadL( 1, trustSettingsPckg ); |
|
175 |
|
176 TBool trusted = trustSettingsPckg().iTrusted; |
|
177 |
|
178 iStatus = KRequestPending; |
|
179 iMessage = aMessage; |
|
180 iPhase = ESetTrust; |
|
181 |
|
182 SetActive(); |
|
183 |
|
184 iWimTrustSettingsStore->SetTrust( *iCertInfo, |
|
185 trusted, |
|
186 iStatus ); |
|
187 } |
|
188 |
|
189 // ----------------------------------------------------------------------------- |
|
190 // CWimTrustSettingsHandler::SetDefaultTrustSettingsL |
|
191 // Set default trust settings for given certificate. If certificate not |
|
192 // found from database new entry is inserted. |
|
193 // ----------------------------------------------------------------------------- |
|
194 // |
|
195 void CWimTrustSettingsHandler::SetDefaultTrustSettingsL( |
|
196 const RMessage2& aMessage ) |
|
197 { |
|
198 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::SetDefaultTrustSettingsL | Begin")); |
|
199 |
|
200 TPckgBuf<TWimCertInfoPckg> pckg; |
|
201 aMessage.ReadL( 0, pckg ); |
|
202 |
|
203 TBool addApps = aMessage.Int1(); |
|
204 |
|
205 __ASSERT_DEBUG( iCertInfo == NULL, User::Panic( KWimTrustSettPanic, KErrGeneral ) ); |
|
206 iCertInfo = CWimCertInfo::InternalizeL( pckg() ); |
|
207 |
|
208 iStatus = KRequestPending; |
|
209 iMessage = aMessage; |
|
210 iPhase = ESetDefaultTrustSettings; |
|
211 SetActive(); |
|
212 iWimTrustSettingsStore->SetDefaultTrustSettings( *iCertInfo, |
|
213 addApps, |
|
214 iStatus ); |
|
215 } |
|
216 |
|
217 // ----------------------------------------------------------------------------- |
|
218 // CWimTrustSettingsHandler::RemoveTrustSettingsL |
|
219 // Remove trust settings of given certificate. If certificate |
|
220 // is not found, return with status.Int() = KErrNotFound |
|
221 // ----------------------------------------------------------------------------- |
|
222 // |
|
223 void CWimTrustSettingsHandler::RemoveTrustSettingsL( const RMessage2& aMessage ) |
|
224 { |
|
225 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::RemoveTrustSettingsL | Begin")); |
|
226 |
|
227 TPckgBuf<TWimCertInfoPckg> pckg; |
|
228 aMessage.ReadL( 0, pckg ); |
|
229 |
|
230 __ASSERT_DEBUG( iCertInfo == NULL, User::Panic( KWimTrustSettPanic, KErrGeneral ) ); |
|
231 iCertInfo = CWimCertInfo::InternalizeL( pckg() ); |
|
232 |
|
233 iStatus = KRequestPending; |
|
234 iMessage = aMessage; |
|
235 iPhase = ERemoveTrustSettings; |
|
236 SetActive(); |
|
237 iWimTrustSettingsStore->RemoveTrustSettings( *iCertInfo, |
|
238 iStatus ); |
|
239 } |
|
240 |
|
241 // ----------------------------------------------------------------------------- |
|
242 // CWimTrustSettingsHandler::CancelDoing |
|
243 // Cancel ongoing TrustSettingsStore operation |
|
244 // ----------------------------------------------------------------------------- |
|
245 // |
|
246 void CWimTrustSettingsHandler::CancelDoing() |
|
247 { |
|
248 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::CancelDoing | Begin")); |
|
249 |
|
250 iWimTrustSettingsStore->CancelDoing(); |
|
251 } |
|
252 |
|
253 // ----------------------------------------------------------------------------- |
|
254 // CWimTrustSettingsHandler::RunL |
|
255 // Complete asynchronous call |
|
256 // ----------------------------------------------------------------------------- |
|
257 // |
|
258 void CWimTrustSettingsHandler::RunL() |
|
259 { |
|
260 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::RunL | Begin")); |
|
261 |
|
262 delete iCertInfo; |
|
263 iCertInfo = NULL; |
|
264 |
|
265 switch ( iPhase ) |
|
266 { |
|
267 case EGetTrustSettings: |
|
268 { |
|
269 TInt applicationCount = iApplications.Count(); |
|
270 |
|
271 // Check that there is no more apps than allocated in array for |
|
272 // If there is more applications than there is space in array |
|
273 // complete message and return |
|
274 if ( applicationCount > KMaxApplicationCount ) |
|
275 { |
|
276 iMessage.Complete( KErrOverflow ); |
|
277 iApplications.Close(); |
|
278 return; |
|
279 } |
|
280 |
|
281 TPckgBuf<TTrustSettings> trustSettings; |
|
282 iMessage.ReadL( 1, trustSettings ); |
|
283 trustSettings().iTrusted = iTrusted; |
|
284 trustSettings().iApplicationCount = iApplications.Count(); |
|
285 |
|
286 for ( TInt i = 0; i < iApplications.Count(); i++ ) |
|
287 { |
|
288 trustSettings().iUids[i] = iApplications[i].iUid; |
|
289 } |
|
290 |
|
291 iApplications.Close(); |
|
292 iMessage.WriteL( 1, trustSettings ); |
|
293 break; |
|
294 } |
|
295 |
|
296 case ESetDefaultTrustSettings: // Flow through |
|
297 case ESetApplicability: // Flow through |
|
298 case ESetTrust: // Flow through |
|
299 case ERemoveTrustSettings: |
|
300 { |
|
301 break; |
|
302 } |
|
303 |
|
304 default: |
|
305 { |
|
306 break; |
|
307 } |
|
308 } |
|
309 |
|
310 iMessage.Complete( iStatus.Int() ); |
|
311 } |
|
312 |
|
313 // ----------------------------------------------------------------------------- |
|
314 // CWimTrustSettingsHandler::DoCancel |
|
315 // |
|
316 // ----------------------------------------------------------------------------- |
|
317 // |
|
318 void CWimTrustSettingsHandler::DoCancel() |
|
319 { |
|
320 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::DoCancel | Begin")); |
|
321 } |
|
322 |
|
323 // ----------------------------------------------------------------------------- |
|
324 // CWimTrustSettingsHandler::RunError |
|
325 // Handle trapped leave in RunL. Complete message with leave error code and |
|
326 // close open resources that need be freed. |
|
327 // ----------------------------------------------------------------------------- |
|
328 // |
|
329 TInt CWimTrustSettingsHandler::RunError( TInt aError ) |
|
330 { |
|
331 _WIMTRACE(_L("WIM | WIMServer | CWimTrustSettingsHandler::RunError | Begin")); |
|
332 |
|
333 iMessage.Complete( aError ); |
|
334 iApplications.Close(); |
|
335 return KErrNone; |
|
336 } |
|
337 |
|
338 // End of File |