|
1 /* |
|
2 * Copyright (c) 2008 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: HTTP plugin framework implementation |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <wmdrmdlatypes.h> |
|
20 #include <wmdrmdlahttpplugin.h> |
|
21 #include <wmdrmdlauinotifier.h> |
|
22 #include "wmdrmdlahttpmeteringpluginfw.h" |
|
23 #include "wmdrmdlahttpfwpluginresolver.h" |
|
24 #include "wmdrmdlaui.h" |
|
25 |
|
26 #define _LOGGING_FILE L"wmdrmdla.txt" |
|
27 #include "logfn.h" |
|
28 |
|
29 // ======== MEMBER FUNCTIONS ======== |
|
30 |
|
31 // --------------------------------------------------------------------------- |
|
32 // CWmDrmDlaHttpMeteringPluginFw::ConstructL |
|
33 // --------------------------------------------------------------------------- |
|
34 // |
|
35 void CWmDrmDlaHttpMeteringPluginFw::ConstructL() |
|
36 { |
|
37 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::ConstructL" ); |
|
38 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
39 } |
|
40 |
|
41 // --------------------------------------------------------------------------- |
|
42 // CWmDrmDlaHttpMeteringPluginFw::CWmDrmDlaHttpMeteringPluginFw |
|
43 // --------------------------------------------------------------------------- |
|
44 // |
|
45 CWmDrmDlaHttpMeteringPluginFw::CWmDrmDlaHttpMeteringPluginFw() |
|
46 : CActive( EPriorityStandard ), |
|
47 iState( CWmDrmDlaHttpMeteringPluginFw::EIdle ) |
|
48 { |
|
49 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::CWmDrmDlaHttpMeteringPluginFw" ); |
|
50 CActiveScheduler::Add( this ); |
|
51 } |
|
52 |
|
53 // --------------------------------------------------------------------------- |
|
54 // CWmDrmDlaHttpMeteringPluginFw::NewL |
|
55 // --------------------------------------------------------------------------- |
|
56 // |
|
57 CWmDrmDlaHttpMeteringPluginFw* CWmDrmDlaHttpMeteringPluginFw::NewL() |
|
58 { |
|
59 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::NewL" ); |
|
60 CWmDrmDlaHttpMeteringPluginFw* self = |
|
61 CWmDrmDlaHttpMeteringPluginFw::NewLC(); |
|
62 CleanupStack::Pop( self ); |
|
63 return self; |
|
64 } |
|
65 |
|
66 |
|
67 // --------------------------------------------------------------------------- |
|
68 // CWmDrmDlaHttpMeteringPluginFw::NewLC |
|
69 // --------------------------------------------------------------------------- |
|
70 // |
|
71 CWmDrmDlaHttpMeteringPluginFw* CWmDrmDlaHttpMeteringPluginFw::NewLC() |
|
72 { |
|
73 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::NewLC" ); |
|
74 CWmDrmDlaHttpMeteringPluginFw* self = |
|
75 new( ELeave ) CWmDrmDlaHttpMeteringPluginFw; |
|
76 CleanupStack::PushL( self ); |
|
77 self->ConstructL(); |
|
78 return self; |
|
79 } |
|
80 |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CWmDrmDlaHttpMeteringPluginFw::~CWmDrmDlaHttpMeteringPluginFw |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CWmDrmDlaHttpMeteringPluginFw::~CWmDrmDlaHttpMeteringPluginFw() |
|
87 { |
|
88 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::~CWmDrmDlaHttpMeteringPluginFw" ); |
|
89 CancelMetering(); |
|
90 delete iHttpPlugin; |
|
91 delete iUiNotifier; |
|
92 delete iIdle; |
|
93 delete iMeteringChallenge; |
|
94 delete iMeteringUrl; |
|
95 delete iMeteringResponse; |
|
96 } |
|
97 |
|
98 // --------------------------------------------------------------------------- |
|
99 // CWmDrmDlaHttpMeteringPluginFw::ProcessMeteringCertificate |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 void CWmDrmDlaHttpMeteringPluginFw::ProcessMeteringCertificate( |
|
103 const TDesC8& aCertificate, |
|
104 TRequestStatus& aStatus ) |
|
105 { |
|
106 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::ProcessMeteringCertificate" ); |
|
107 |
|
108 TRequestStatus *status = &aStatus; |
|
109 aStatus = KRequestPending; |
|
110 if ( iState != CWmDrmDlaHttpMeteringPluginFw::EIdle ) |
|
111 { |
|
112 User::RequestComplete( status, KErrInUse ); |
|
113 return; |
|
114 } |
|
115 |
|
116 iClientStatus = &aStatus; |
|
117 iCertificate = &aCertificate; |
|
118 iState = CWmDrmDlaHttpMeteringPluginFw::EResolvingHttpPlugin; |
|
119 CompleteSelf(); |
|
120 } |
|
121 |
|
122 // --------------------------------------------------------------------------- |
|
123 // CWmDrmDlaHttpMeteringPluginFw::CancelMetering |
|
124 // --------------------------------------------------------------------------- |
|
125 // |
|
126 void CWmDrmDlaHttpMeteringPluginFw::CancelMetering() |
|
127 { |
|
128 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::CancelMetering" ); |
|
129 if ( iHttpPlugin ) |
|
130 { |
|
131 iHttpPlugin->CancelMetering(); |
|
132 } |
|
133 Cancel(); |
|
134 if ( iUiNotifier ) |
|
135 { |
|
136 TRAP_IGNORE( iUiNotifier->HandleErrorL( KErrCancel ) ); |
|
137 } |
|
138 CompleteClientRequest( KErrCancel ); |
|
139 Reset(); |
|
140 } |
|
141 |
|
142 // --------------------------------------------------------------------------- |
|
143 // CWmDrmDlaHttpMeteringPluginFw::SetIapId |
|
144 // --------------------------------------------------------------------------- |
|
145 // |
|
146 void CWmDrmDlaHttpMeteringPluginFw::SetIapId( TInt aIapId ) |
|
147 { |
|
148 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::SetIapId" ); |
|
149 LOG2( "aIapId: %d", aIapId ); |
|
150 iIapId = aIapId; |
|
151 if ( iHttpPlugin ) |
|
152 { |
|
153 iHttpPlugin->SetIapId( iIapId ); |
|
154 } |
|
155 } |
|
156 |
|
157 // --------------------------------------------------------------------------- |
|
158 // CWmDrmDlaHttpMeteringPluginFw::DoCancel |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CWmDrmDlaHttpMeteringPluginFw::DoCancel() |
|
162 { |
|
163 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::DoCancel" ); |
|
164 } |
|
165 |
|
166 // --------------------------------------------------------------------------- |
|
167 // CWmDrmDlaHttpMeteringPluginFw::RunL |
|
168 // --------------------------------------------------------------------------- |
|
169 // |
|
170 void CWmDrmDlaHttpMeteringPluginFw::RunL() |
|
171 { |
|
172 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::RunL" ); |
|
173 LOG2( "iState: %d", iState ); |
|
174 LOG2( "iStatus.Int(): %d", iStatus.Int() ); |
|
175 if ( iStatus.Int() != KErrNone ) |
|
176 { |
|
177 HandleErrorL( iStatus.Int() ); |
|
178 } |
|
179 |
|
180 switch ( iState ) |
|
181 { |
|
182 case CWmDrmDlaHttpMeteringPluginFw::EResolvingHttpPlugin: |
|
183 ResolvingHttpPluginHandlerL(); |
|
184 break; |
|
185 |
|
186 case CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringChallenge: |
|
187 RetrievingMeteringChallenge(); |
|
188 break; |
|
189 |
|
190 case CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringChallenge: |
|
191 ProcessingMeteringChallenge(); |
|
192 break; |
|
193 |
|
194 case CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringResponse: |
|
195 RetrievingMeteringResponse(); |
|
196 break; |
|
197 |
|
198 case CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringResponse: |
|
199 ProcessingMeteringResponse(); |
|
200 break; |
|
201 |
|
202 case CWmDrmDlaHttpMeteringPluginFw::EMeteringFinished: |
|
203 MeteringFinished(); |
|
204 break; |
|
205 |
|
206 default: |
|
207 ASSERT( EFalse ); |
|
208 break; |
|
209 } |
|
210 } |
|
211 |
|
212 // --------------------------------------------------------------------------- |
|
213 // CWmDrmDlaHttpMeteringPluginFw::RunError |
|
214 // --------------------------------------------------------------------------- |
|
215 // |
|
216 TInt CWmDrmDlaHttpMeteringPluginFw::RunError( TInt aError ) |
|
217 { |
|
218 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::RunError" ); |
|
219 LOG2( "aError: %d", aError ); |
|
220 CompleteClientRequest( aError ); |
|
221 Reset(); |
|
222 return KErrNone; |
|
223 } |
|
224 |
|
225 // --------------------------------------------------------------------------- |
|
226 // CWmDrmDlaHttpMeteringPluginFw::UserCancellation |
|
227 // --------------------------------------------------------------------------- |
|
228 // |
|
229 void CWmDrmDlaHttpMeteringPluginFw::UserCancellation() |
|
230 { |
|
231 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::UserCancellation"); |
|
232 TCallBack callBack( CWmDrmDlaHttpMeteringPluginFw::AsyncCancel, |
|
233 this ); |
|
234 iIdle->Start( callBack ); |
|
235 } |
|
236 |
|
237 // ---------------------------------------------------------------------------- |
|
238 // CWmDrmDlaHttpMeteringPluginFw::CompleteSelf |
|
239 // ---------------------------------------------------------------------------- |
|
240 // |
|
241 void CWmDrmDlaHttpMeteringPluginFw::CompleteSelf() |
|
242 { |
|
243 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::CompleteSelf" ); |
|
244 if ( !IsActive() ) |
|
245 { |
|
246 TRequestStatus* status = &iStatus; |
|
247 User::RequestComplete( status, KErrNone ); |
|
248 SetActive(); |
|
249 } |
|
250 } |
|
251 |
|
252 // ---------------------------------------------------------------------------- |
|
253 // CWmDrmDlaHandlerImpl::CompleteClientRequest |
|
254 // ---------------------------------------------------------------------------- |
|
255 // |
|
256 void CWmDrmDlaHttpMeteringPluginFw::CompleteClientRequest( TInt aError ) |
|
257 { |
|
258 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::CompleteClientRequest" ); |
|
259 LOG2( "aError: %d", aError ); |
|
260 if ( iClientStatus ) |
|
261 { |
|
262 User::RequestComplete( iClientStatus, aError ); |
|
263 iClientStatus = NULL; |
|
264 } |
|
265 } |
|
266 |
|
267 // ---------------------------------------------------------------------------- |
|
268 // CWmDrmDlaHttpMeteringPluginFw::::Reset |
|
269 // ---------------------------------------------------------------------------- |
|
270 // |
|
271 void CWmDrmDlaHttpMeteringPluginFw::Reset() |
|
272 { |
|
273 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::Reset" ); |
|
274 delete iHttpPlugin; |
|
275 iHttpPlugin = NULL; |
|
276 delete iUiNotifier; |
|
277 iUiNotifier = NULL; |
|
278 delete iMeteringChallenge; |
|
279 iMeteringChallenge = NULL; |
|
280 delete iMeteringUrl; |
|
281 iMeteringUrl = NULL; |
|
282 delete iMeteringResponse; |
|
283 iMeteringResponse = NULL; |
|
284 iCertificate = NULL; |
|
285 iState = CWmDrmDlaHttpMeteringPluginFw::EIdle; |
|
286 } |
|
287 |
|
288 // ---------------------------------------------------------------------------- |
|
289 // CWmDrmDlaHttpMeteringPluginFw::ResolvingHttpPluginHandlerL |
|
290 // ---------------------------------------------------------------------------- |
|
291 // |
|
292 void CWmDrmDlaHttpMeteringPluginFw::ResolvingHttpPluginHandlerL() |
|
293 { |
|
294 TInt err( KErrNone ); |
|
295 |
|
296 LOGFNR( "CWmDrmDlaHttpMeteringPluginFw::ResolvingHttpPluginHandlerL", err ); |
|
297 |
|
298 TRAP( err, ResolveHttpPluginWithCertificateL( *iCertificate ) ); |
|
299 if ( err ) |
|
300 { |
|
301 HandleErrorL( err ); |
|
302 } |
|
303 iState = CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringChallenge; |
|
304 CompleteSelf(); |
|
305 } |
|
306 |
|
307 // ---------------------------------------------------------------------------- |
|
308 // CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringChallengeL |
|
309 // ---------------------------------------------------------------------------- |
|
310 // |
|
311 void CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringChallenge() |
|
312 { |
|
313 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringChallenge" ); |
|
314 delete iMeteringChallenge; |
|
315 iMeteringChallenge = NULL; |
|
316 delete iMeteringUrl; |
|
317 iMeteringUrl = NULL; |
|
318 SetActive(); |
|
319 iState = CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringChallenge; |
|
320 TRequestStatus* status = &iStatus; |
|
321 User::RequestComplete( status, KErrNotSupported ); |
|
322 } |
|
323 |
|
324 // ---------------------------------------------------------------------------- |
|
325 // CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringChallengeL |
|
326 // ---------------------------------------------------------------------------- |
|
327 // |
|
328 void CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringChallenge() |
|
329 { |
|
330 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringChallenge" ); |
|
331 iHttpPlugin->ProcessMeteringChallenge( *iMeteringChallenge, |
|
332 *iMeteringUrl, |
|
333 iStatus ); |
|
334 SetActive(); |
|
335 iState = CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringResponse; |
|
336 } |
|
337 |
|
338 // ---------------------------------------------------------------------------- |
|
339 // CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringResponseL |
|
340 // ---------------------------------------------------------------------------- |
|
341 // |
|
342 void CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringResponse() |
|
343 { |
|
344 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::RetrievingMeteringResponse" ); |
|
345 delete iMeteringResponse; |
|
346 iMeteringResponse = NULL; |
|
347 iHttpPlugin->GetMeteringResponse( iMeteringResponse, iStatus ); |
|
348 SetActive(); |
|
349 iState = CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringResponse; |
|
350 } |
|
351 |
|
352 // ---------------------------------------------------------------------------- |
|
353 // CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringResponseL |
|
354 // ---------------------------------------------------------------------------- |
|
355 // |
|
356 void CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringResponse() |
|
357 { |
|
358 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::ProcessingMeteringResponse" ); |
|
359 SetActive(); |
|
360 iState = CWmDrmDlaHttpMeteringPluginFw::EMeteringFinished; |
|
361 TRequestStatus* status = &iStatus; |
|
362 User::RequestComplete( status, KErrNotSupported ); |
|
363 } |
|
364 |
|
365 // ---------------------------------------------------------------------------- |
|
366 // CWmDrmDlaHttpMeteringPluginFw::MeteringFinishedL |
|
367 // ---------------------------------------------------------------------------- |
|
368 // |
|
369 void CWmDrmDlaHttpMeteringPluginFw::MeteringFinished() |
|
370 { |
|
371 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::MeteringFinished" ); |
|
372 LOG2( "iPartialMetering: %d", iPartialMetering ); |
|
373 if ( iPartialMetering ) |
|
374 { |
|
375 iState = CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringChallenge; |
|
376 CompleteSelf(); |
|
377 } |
|
378 else |
|
379 { |
|
380 iHttpPlugin->MeteringFinished(); |
|
381 CompleteClientRequest( KErrNone ); |
|
382 Reset(); |
|
383 } |
|
384 } |
|
385 |
|
386 // --------------------------------------------------------------------------- |
|
387 // CWmDrmDlaHttpMeteringPluginFw::::ResolveHttpPluginWithCertificateL |
|
388 // --------------------------------------------------------------------------- |
|
389 // |
|
390 void CWmDrmDlaHttpMeteringPluginFw::ResolveHttpPluginWithCertificateL( |
|
391 const TDesC8& aCertificate ) |
|
392 { |
|
393 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::ResolveHttpPluginL" ); |
|
394 |
|
395 delete iHttpPlugin; |
|
396 iHttpPlugin = NULL; |
|
397 delete iUiNotifier; |
|
398 iUiNotifier = NULL; |
|
399 |
|
400 WmDrmDlaHttpFwPluginResolver::ResolveHttpPluginWithCertificateL( |
|
401 aCertificate, iHttpPlugin, iUiNotifier ); |
|
402 |
|
403 //Set cancel observer for ui plugin |
|
404 if ( iUiNotifier ) |
|
405 { |
|
406 iUiNotifier->SetCancelObserver( this ); |
|
407 } |
|
408 //Set iap for http plugin |
|
409 if ( iIapId ) |
|
410 { |
|
411 iHttpPlugin->SetIapId( iIapId ); |
|
412 } |
|
413 } |
|
414 |
|
415 // ---------------------------------------------------------------------------- |
|
416 // CWmDrmDlaHttpMeteringPluginFw::HandleErrorL |
|
417 // ---------------------------------------------------------------------------- |
|
418 // |
|
419 void CWmDrmDlaHttpMeteringPluginFw::HandleErrorL( TInt aError ) |
|
420 { |
|
421 TInt err( KErrNone ); |
|
422 |
|
423 LOGFNR( "CWmDrmDlaHttpMeteringPluginFw::HandleErrorL", err ); |
|
424 LOG2( "iState: %d", iState ); |
|
425 LOG2( "aError: %d", aError ); |
|
426 |
|
427 if ( iUiNotifier ) |
|
428 { |
|
429 TRAP( err, iUiNotifier->HandleErrorL( aError ) ); |
|
430 } |
|
431 |
|
432 switch ( iState ) |
|
433 { |
|
434 case CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringChallenge: |
|
435 break; |
|
436 |
|
437 case CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringChallenge: |
|
438 break; |
|
439 |
|
440 case CWmDrmDlaHttpMeteringPluginFw::ERetrievingMeteringResponse: |
|
441 break; |
|
442 |
|
443 case CWmDrmDlaHttpMeteringPluginFw::EProcessingMeteringResponse: |
|
444 break; |
|
445 |
|
446 case CWmDrmDlaHttpMeteringPluginFw::EMeteringFinished: |
|
447 break; |
|
448 |
|
449 default: |
|
450 break; |
|
451 } |
|
452 |
|
453 User::Leave( aError ); |
|
454 } |
|
455 |
|
456 // --------------------------------------------------------------------------- |
|
457 // CWmDrmDlaHttpMeteringPluginFw::AsyncCancel |
|
458 // --------------------------------------------------------------------------- |
|
459 // |
|
460 TInt CWmDrmDlaHttpMeteringPluginFw::AsyncCancel( TAny* aPtr ) |
|
461 { |
|
462 LOGFN( "CWmDrmDlaHttpMeteringPluginFw::AsyncCancel"); |
|
463 CWmDrmDlaHttpMeteringPluginFw* meteringFw = |
|
464 static_cast<CWmDrmDlaHttpMeteringPluginFw*>( aPtr ); |
|
465 meteringFw->CancelMetering(); |
|
466 return EFalse; |
|
467 } |