|
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: WMDRM DLA Default Http License Acquisition |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <chttpformencoder.h> |
|
20 #include <httpstringconstants.h> |
|
21 #include <httperr.h> |
|
22 #include <http/rhttpheaders.h> |
|
23 #include <http/thttphdrfielditer.h> |
|
24 #include <stringpool.h> |
|
25 #include <escapeutils.h> |
|
26 #include <wmdrmdlatypes.h> |
|
27 #include <wmdrmdlauinotifier.h> |
|
28 #include "asf.h" |
|
29 #include "wmdrmdladefaultlicacq.h" |
|
30 #include "wmdrmdladefaulthttpplugin.h" |
|
31 #include "wmdrmdlabrowserviewhandler.h" |
|
32 #include "wmdrmdlabrowserobserver.h" |
|
33 #include "wmdrmdladefaulthttpmanager.h" |
|
34 |
|
35 #define _LOGGING_FILE L"wmdrmdladefaulthttpplugin.txt" |
|
36 #include "logfn.h" |
|
37 |
|
38 // CONSTANTS |
|
39 _LIT8( KDefaultIdentifier8, "camese" ); |
|
40 _LIT8( KDefaultIdentifier, "c\0a\0m\0e\0s\0e\0" ); |
|
41 _LIT8( KNonSilentIdentifier, "n\0o\0n\0s\0i\0l\0e\0n\0t" ); |
|
42 |
|
43 _LIT8( KAcceptHeader8, "*/*" ); |
|
44 _LIT8( KAcceptLanguageHeader8, "en-us" ); |
|
45 _LIT8( KPostContentTypeHeader8, "application/x-www-form-urlencoded" ); |
|
46 |
|
47 _LIT8( KDataTypeLicenseResponse, "application/vnd.ms-wmdrm.lic-resp" ); |
|
48 _LIT8( KDataTypeHtml, "text/html" ); |
|
49 |
|
50 _LIT8( KGetLicenseChallengeParam8, "challenge" ); |
|
51 _LIT8( KGetNonSilentParam8, "nonsilent" ); |
|
52 _LIT8( KLicenseStatusParam8, "License1Status" ); |
|
53 |
|
54 _LIT8( KTIDHeader8, "TID=" ); |
|
55 _LIT8( KQueryTag8, "?" ); |
|
56 _LIT8( KNonSilentValue, "1" ); |
|
57 |
|
58 _LIT8( KAmpersand, "&" ); |
|
59 _LIT8( KChallenge, "nonsilent=1&challenge=" ); |
|
60 |
|
61 _LIT8( KHRESULTFormat,"0x%08x" ); |
|
62 const TInt KHRESULTFormatLength = 10; // '0x' + %08x |
|
63 const TUint KHRESULTBase = 0x80000000; |
|
64 const TInt KHRESULTErrorMask = 0x01 << 31 | 0x04 << 16; |
|
65 |
|
66 // ======== LOCAL FUNCTIONS ======== |
|
67 |
|
68 // ======== MEMBER FUNCTIONS ======== |
|
69 |
|
70 // --------------------------------------------------------------------------- |
|
71 // CWmDrmDlaDefaultLicAcq::ConstructL |
|
72 // --------------------------------------------------------------------------- |
|
73 // |
|
74 void CWmDrmDlaDefaultLicAcq::ConstructL() |
|
75 { |
|
76 LOGFN( "CWmDrmDlaDefaultLicAcq::ConstructL" ); |
|
77 iHttpManager = CWmDrmDlaDefaultHttpManager::NewL( *this ); |
|
78 iHttpManager->SetKeepAlive( ETrue ); |
|
79 iIdle = CIdle::NewL( CActive::EPriorityIdle ); |
|
80 } |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CWmDrmDlaDefaultLicAcq::CWmDrmDlaDefaultLicAcq |
|
84 // --------------------------------------------------------------------------- |
|
85 // |
|
86 CWmDrmDlaDefaultLicAcq::CWmDrmDlaDefaultLicAcq( |
|
87 CWmDrmDlaDefaultHttpPlugin* aPlugin ) |
|
88 : iState( CWmDrmDlaDefaultLicAcq::ENotActive ), iPlugin( aPlugin ) |
|
89 |
|
90 { |
|
91 LOGFN( "CWmDrmDlaDefaultLicAcq::CWmDrmDlaDefaultLicAcq" ); |
|
92 } |
|
93 |
|
94 // --------------------------------------------------------------------------- |
|
95 // CWmDrmDlaDefaultLicAcq::NewL |
|
96 // --------------------------------------------------------------------------- |
|
97 // |
|
98 CWmDrmDlaDefaultLicAcq* CWmDrmDlaDefaultLicAcq::NewL( |
|
99 CWmDrmDlaDefaultHttpPlugin* aPlugin ) |
|
100 { |
|
101 LOGFN( "CWmDrmDlaDefaultLicAcq::NewL" ); |
|
102 CWmDrmDlaDefaultLicAcq* self |
|
103 = new( ELeave ) CWmDrmDlaDefaultLicAcq( aPlugin ); |
|
104 CleanupStack::PushL( self ); |
|
105 self->ConstructL(); |
|
106 CleanupStack::Pop( self ); |
|
107 return self; |
|
108 } |
|
109 |
|
110 // --------------------------------------------------------------------------- |
|
111 // CWmDrmDlaDefaultLicAcq::~CWmDrmDlaDefaultLicAcq |
|
112 // --------------------------------------------------------------------------- |
|
113 // |
|
114 CWmDrmDlaDefaultLicAcq::~CWmDrmDlaDefaultLicAcq() |
|
115 { |
|
116 LOGFN( "CWmDrmDlaDefaultLicAcq::~CWmDrmDlaDefaultLicAcq" ); |
|
117 delete iIdle; |
|
118 delete iBrowserViewHandler; |
|
119 delete iHttpManager; |
|
120 delete iFormEncoder; |
|
121 delete iPostData; |
|
122 delete iLicenseChallenge; |
|
123 delete iLicenseResponse; |
|
124 delete iLicenseServerUrl16; |
|
125 delete iLicenseServerUrl; |
|
126 delete iHtmlData; |
|
127 } |
|
128 |
|
129 // --------------------------------------------------------------------------- |
|
130 // CWmDrmDlaDefaultLicAcq::SupportedFileL |
|
131 // --------------------------------------------------------------------------- |
|
132 // |
|
133 TBool CWmDrmDlaDefaultLicAcq::SupportedFileL( |
|
134 const RFile& aFile, |
|
135 CWmDrmDlaUiNotifier*& aUiNotifier) |
|
136 { |
|
137 TInt err( KErrNone ); |
|
138 TBool supported( EFalse ); |
|
139 |
|
140 LOGFNR( "CWmDrmDlaDefaultLicAcq::SupportedFileL", err ); |
|
141 |
|
142 //Check that the file is valid ASF-file and that the extented content |
|
143 //encryption object of the file includes MS test site identifier |
|
144 CAsf* asf( NULL ); |
|
145 TRAP( err, asf = CAsf::NewL( aFile ) ); |
|
146 if ( !err ) |
|
147 { |
|
148 supported = iPlugin->Supported( *asf->iExtendedContentEncryptionObject, |
|
149 KDefaultIdentifier ); |
|
150 delete asf; |
|
151 } |
|
152 |
|
153 //If file is recognized, then initialize UiNotifier and transfer its |
|
154 //ownership to the FW |
|
155 if ( supported ) |
|
156 { |
|
157 iPlugin->InitializeUiNotifierL(); |
|
158 aUiNotifier = iPlugin->UiNotifier(); |
|
159 } |
|
160 LOG2( "supported: %d", supported ); |
|
161 return supported; |
|
162 } |
|
163 |
|
164 // --------------------------------------------------------------------------- |
|
165 // CWmDrmDlaDefaultLicAcq::SupportedDrmHeaderL |
|
166 // --------------------------------------------------------------------------- |
|
167 // |
|
168 TBool CWmDrmDlaDefaultLicAcq::SupportedDrmHeaderL( |
|
169 const TDesC8& aHeader, |
|
170 CWmDrmDlaUiNotifier*& aUiNotifier ) |
|
171 { |
|
172 LOGFN( "CWmDrmDlaDefaultLicAcq::SupportedDrmHeaderL" ); |
|
173 |
|
174 //Check that the drm header includes MS test site identifier |
|
175 TBool supported( iPlugin->Supported( aHeader, KDefaultIdentifier8 ) ); |
|
176 //If header is recognized, then initialize UiNotifier and transfer its |
|
177 //ownership to the FW |
|
178 if ( supported ) |
|
179 { |
|
180 iPlugin->InitializeUiNotifierL(); |
|
181 aUiNotifier = iPlugin->UiNotifier(); |
|
182 } |
|
183 LOG2( "supported: %d", supported ); |
|
184 return supported; |
|
185 } |
|
186 |
|
187 // --------------------------------------------------------------------------- |
|
188 // CWmDrmDlaDefaultLicAcq::SilentL |
|
189 // --------------------------------------------------------------------------- |
|
190 // |
|
191 TBool CWmDrmDlaDefaultLicAcq::SilentL( |
|
192 const RFile& aFile ) |
|
193 { |
|
194 TInt err( KErrNone ); |
|
195 |
|
196 LOGFNR( "CWmDrmDlaDefaultLicAcq::SilentL", err ); |
|
197 |
|
198 //Check is the content silent or not by checking that the extented content |
|
199 //encryption object of the file includes MS test site non-silent identifier |
|
200 iNonSilent = EFalse; |
|
201 CAsf* asf( NULL ); |
|
202 TRAP( err, asf = CAsf::NewL( aFile ) ); |
|
203 if ( !err ) |
|
204 { |
|
205 iNonSilent = |
|
206 iPlugin->Supported( *asf->iExtendedContentEncryptionObject, |
|
207 KNonSilentIdentifier ); |
|
208 delete asf; |
|
209 } |
|
210 iPlugin->UiNotifier()->SetSilent( !iNonSilent ); |
|
211 LOG2( "!iNonSilent: %d", !iNonSilent ); |
|
212 return !iNonSilent; |
|
213 } |
|
214 |
|
215 // --------------------------------------------------------------------------- |
|
216 // CWmDrmDlaDefaultLicAcq::ProcessDrmHeaderL |
|
217 // --------------------------------------------------------------------------- |
|
218 // |
|
219 void CWmDrmDlaDefaultLicAcq::ProcessDrmHeaderL( |
|
220 const TDesC8& /*aDrmHeader*/ ) |
|
221 { |
|
222 LOGFN( "CWmDrmDlaDefaultLicAcq::ProcessDrmHeaderL" ); |
|
223 iPlugin->UiNotifier()->SetProgress( EProcessingDRMHeader ); |
|
224 } |
|
225 |
|
226 // --------------------------------------------------------------------------- |
|
227 // CWmDrmDlaDefaultLicAcq::AcquireLicense |
|
228 // --------------------------------------------------------------------------- |
|
229 // |
|
230 void CWmDrmDlaDefaultLicAcq::AcquireLicense( |
|
231 const TDesC8& aLicenseChallenge, |
|
232 HBufC* aLicenseServerUrl, |
|
233 TRequestStatus& aStatus ) |
|
234 { |
|
235 TInt err( KErrNone ); |
|
236 |
|
237 LOGFNR( "CWmDrmDlaDefaultLicAcq::AcquireLicense", err ); |
|
238 |
|
239 iPlugin->UiNotifier()->SetProgress( ERetrievingLicense ); |
|
240 aStatus = KRequestPending; |
|
241 iClientStatus = &aStatus; |
|
242 |
|
243 delete iLicenseServerUrl; |
|
244 iLicenseServerUrl = NULL; |
|
245 TRAP( err, |
|
246 iLicenseServerUrl = |
|
247 EscapeUtils::ConvertFromUnicodeToUtf8L( *aLicenseServerUrl ) ); |
|
248 if ( !iLicenseServerUrl ) |
|
249 { |
|
250 CompleteClientRequest( err ); |
|
251 return; |
|
252 } |
|
253 delete iLicenseChallenge; |
|
254 iLicenseChallenge = NULL; |
|
255 iLicenseChallenge = aLicenseChallenge.Alloc(); |
|
256 if ( !iLicenseChallenge ) |
|
257 { |
|
258 CompleteClientRequest( KErrNoMemory ); |
|
259 return; |
|
260 } |
|
261 TRAP( err, AcquireLicenseL() ); |
|
262 if ( err ) |
|
263 { |
|
264 CompleteClientRequest( err ); |
|
265 return; |
|
266 } |
|
267 iState = CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge; |
|
268 } |
|
269 |
|
270 // --------------------------------------------------------------------------- |
|
271 // CWmDrmDlaDefaultLicAcq::GetLicenseResponseL |
|
272 // --------------------------------------------------------------------------- |
|
273 // |
|
274 HBufC8* CWmDrmDlaDefaultLicAcq::GetLicenseResponseL() |
|
275 { |
|
276 LOGFN( "CWmDrmDlaDefaultLicAcq::GetLicenseResponseL" ); |
|
277 iPlugin->UiNotifier()->SetProgress( EAddingLicense ); |
|
278 if ( iLicenseResponse ) |
|
279 { |
|
280 return iLicenseResponse->AllocL(); |
|
281 } |
|
282 else |
|
283 { |
|
284 return NULL; |
|
285 } |
|
286 } |
|
287 |
|
288 // --------------------------------------------------------------------------- |
|
289 // CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatus |
|
290 // --------------------------------------------------------------------------- |
|
291 // |
|
292 void CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatus( |
|
293 HBufC8* aTid, |
|
294 const TDesC& /*aUrl*/, |
|
295 TInt aError, |
|
296 TRequestStatus& aStatus ) |
|
297 { |
|
298 TInt err( KErrNone ); |
|
299 |
|
300 LOGFNR( "CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatus", err ); |
|
301 LOG2( "aError: %d", aError ); |
|
302 |
|
303 iPlugin->UiNotifier()->SetProgress( ESendingLicenseStorageStatus ); |
|
304 aStatus = KRequestPending; |
|
305 iClientStatus = &aStatus; |
|
306 |
|
307 if ( !aTid ) |
|
308 { |
|
309 CompleteClientRequest( KErrCorrupt ); |
|
310 return; |
|
311 } |
|
312 |
|
313 TRAP( err, SendLicenseStorageStatusL( *aTid, aError ) ); |
|
314 if ( err ) |
|
315 { |
|
316 CompleteClientRequest( err ); |
|
317 return; |
|
318 } |
|
319 iState = CWmDrmDlaDefaultLicAcq::ESendingStorageStatus; |
|
320 } |
|
321 |
|
322 // --------------------------------------------------------------------------- |
|
323 // CWmDrmDlaDefaultLicAcq::SendDrmHeaderError |
|
324 // --------------------------------------------------------------------------- |
|
325 // |
|
326 void CWmDrmDlaDefaultLicAcq::SendDrmHeaderError( |
|
327 const TDesC& /*aErrorUrl*/, |
|
328 TInt /*aError*/, |
|
329 TRequestStatus& aStatus ) |
|
330 { |
|
331 LOGFN( "CWmDrmDlaDefaultLicAcq::SendDrmHeaderError" ); |
|
332 iPlugin->UiNotifier()->SetProgress( ESendingDrmHeaderStatus ); |
|
333 aStatus = KRequestPending; |
|
334 iClientStatus = &aStatus; |
|
335 CompleteClientRequest( KErrNotSupported ); |
|
336 } |
|
337 |
|
338 // --------------------------------------------------------------------------- |
|
339 // CWmDrmDlaDefaultLicAcq::GetContentUrlL |
|
340 // --------------------------------------------------------------------------- |
|
341 // |
|
342 HBufC* CWmDrmDlaDefaultLicAcq::GetContentUrlL() |
|
343 { |
|
344 LOGFN( "CWmDrmDlaDefaultLicAcq::GetContentUrlL" ); |
|
345 return NULL; |
|
346 } |
|
347 |
|
348 // --------------------------------------------------------------------------- |
|
349 // CWmDrmDlaDefaultLicAcq::GetHtmlDataL |
|
350 // --------------------------------------------------------------------------- |
|
351 // |
|
352 HBufC* CWmDrmDlaDefaultLicAcq::GetHtmlDataL() |
|
353 { |
|
354 LOGFN( "CWmDrmDlaDefaultLicAcq::GetHtmlDataL" ); |
|
355 iPlugin->UiNotifier()->SetProgress( EIdle ); |
|
356 if ( iHtmlData ) |
|
357 { |
|
358 return iHtmlData->AllocL(); |
|
359 } |
|
360 else |
|
361 { |
|
362 return NULL; |
|
363 } |
|
364 } |
|
365 |
|
366 // --------------------------------------------------------------------------- |
|
367 // CWmDrmDlaDefaultLicAcq::CancelLicenseAcquisition |
|
368 // --------------------------------------------------------------------------- |
|
369 // |
|
370 void CWmDrmDlaDefaultLicAcq::CancelLicenseAcquisition() |
|
371 { |
|
372 LOGFN( "CWmDrmDlaDefaultLicAcq::CancelLicenseAcquisition" ); |
|
373 iHttpManager->Stop(); |
|
374 CompleteClientRequest( KErrCancel ); |
|
375 } |
|
376 |
|
377 // --------------------------------------------------------------------------- |
|
378 // CWmDrmDlaDefaultHttpPlugin::SetIapId |
|
379 // --------------------------------------------------------------------------- |
|
380 // |
|
381 void CWmDrmDlaDefaultLicAcq::SetIapId( TInt aIapId ) |
|
382 { |
|
383 LOGFN( "CWmDrmDlaDefaultLicAcq::SetIapId" ); |
|
384 LOG2( "aIapId: %d", aIapId ); |
|
385 iHttpManager->SetIapId( aIapId ); |
|
386 } |
|
387 |
|
388 // ---------------------------------------------------------------------------- |
|
389 // CWmDrmDlaDefaultLicAcq::OnGetUsernamePasswordL |
|
390 // From MHttpManagerObserver |
|
391 // This function is called when using HTTPS authentication. Authentication is |
|
392 // not currently used in the Camese project |
|
393 // ---------------------------------------------------------------------------- |
|
394 // |
|
395 TBool CWmDrmDlaDefaultLicAcq::OnGetUsernamePasswordL( |
|
396 HBufC8*& /*aUsername*/, |
|
397 HBufC8*& /*aPassword*/) |
|
398 { |
|
399 LOGFN( "CWmDrmDlaDefaultLicAcq::OnGetUsernamePasswordL" ); |
|
400 return EFalse; |
|
401 } |
|
402 |
|
403 // ---------------------------------------------------------------------------- |
|
404 // CWmDrmDlaDefaultLicAcq::OnResponseHeadersL |
|
405 // From MHttpManagerObserver |
|
406 // ---------------------------------------------------------------------------- |
|
407 // |
|
408 void CWmDrmDlaDefaultLicAcq::OnResponseHeadersL( |
|
409 const RHTTPResponse& /*aResponse*/, |
|
410 const RHTTPHeaders& aHeaders, |
|
411 const RStringPool& aStringPool, |
|
412 TInt aHttpStatus ) |
|
413 { |
|
414 LOGFN( "CWmDrmDlaDefaultLicAcq::OnResponseHeadersL" ); |
|
415 LOG2( "iState: %d", iState ); |
|
416 LOG2( "aHttpStatus: %d", aHttpStatus ); |
|
417 //Redirection in license acquisition |
|
418 if ( aHttpStatus >= HTTPStatus::EMultipleChoices && |
|
419 aHttpStatus < HTTPStatus::EBadRequest && |
|
420 iState == CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge ) |
|
421 { |
|
422 HandleRedirectionHeadersL( aHeaders, aStringPool ); |
|
423 } |
|
424 //License acquisition |
|
425 else if ( aHttpStatus == HTTPStatus::EOk && |
|
426 iState != CWmDrmDlaDefaultLicAcq::ESendingStorageStatus ) |
|
427 { |
|
428 HandleLicenseAcquistionHeaders( aHeaders, aStringPool ); |
|
429 } |
|
430 //Sending license storage status or error |
|
431 else |
|
432 { |
|
433 iHttpStatus = aHttpStatus; |
|
434 } |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------------------------- |
|
438 // CWmDrmDlaDefaultLicAcq::OnResponseBodyDataL |
|
439 // From MHttpManagerObserver |
|
440 // ---------------------------------------------------------------------------- |
|
441 // |
|
442 void CWmDrmDlaDefaultLicAcq::OnResponseBodyDataL( const TPtrC8 aDataChunk ) |
|
443 { |
|
444 LOGFN( "CWmDrmDlaDefaultLicAcq::OnResponseBodyDataL" ); |
|
445 LOG2( "iState: %d", iState ); |
|
446 LOG2( "iHttpStatus: %d", iHttpStatus ); |
|
447 //If we are acquiring license and response headers are OK, |
|
448 //then save the response. |
|
449 if ( iHttpStatus == HTTPStatus::EOk && |
|
450 iState == CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge ) |
|
451 { |
|
452 if ( !iLicenseResponse ) |
|
453 { |
|
454 iLicenseResponse = HBufC8::NewL( aDataChunk.Length() ); |
|
455 } |
|
456 else |
|
457 { |
|
458 iLicenseResponse = |
|
459 iLicenseResponse->ReAllocL( iLicenseResponse->Length() + |
|
460 aDataChunk.Length() ); |
|
461 } |
|
462 iLicenseResponse->Des().Append( aDataChunk ); |
|
463 } |
|
464 } |
|
465 |
|
466 // ---------------------------------------------------------------------------- |
|
467 // CWmDrmDlaDefaultLicAcq::OnTransactionComplete |
|
468 // From MHttpManagerObserver |
|
469 // ---------------------------------------------------------------------------- |
|
470 // |
|
471 void CWmDrmDlaDefaultLicAcq::OnTransactionComplete( TInt aSystemError ) |
|
472 { |
|
473 LOGFN( "CWmDrmDlaDefaultLicAcq::OnTransactionComplete" ); |
|
474 LOG2( "iState: %d", iState ); |
|
475 LOG2( "aSystemError: %d", aSystemError ); |
|
476 LOG2( "iHttpStatus: %d", iHttpStatus ); |
|
477 TInt err( KErrNone ); |
|
478 //Transaction succeeded |
|
479 if ( iHttpStatus == HTTPStatus::EOk && !aSystemError ) |
|
480 { |
|
481 //If redirection happened, then start a new license acquisition |
|
482 //asynchronously to a new location. |
|
483 if ( iState == CWmDrmDlaDefaultLicAcq::ERedirection ) |
|
484 { |
|
485 TCallBack callBack( CWmDrmDlaDefaultLicAcq::Redirection, |
|
486 this ); |
|
487 iIdle->Start( callBack ); |
|
488 iState = CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge; |
|
489 } |
|
490 //If license acquisition is non-silent, then launch a browser view. |
|
491 else if ( iState == |
|
492 CWmDrmDlaDefaultLicAcq::ENonSilentLicenseAcquisition ) |
|
493 { |
|
494 TRAP( err, LaunchBrowserViewL() ); |
|
495 if ( err ) |
|
496 { |
|
497 CompleteClientRequest( err ); |
|
498 return; |
|
499 } |
|
500 iPlugin->UiNotifier()->SetProgress( EIdle ); |
|
501 iState = CWmDrmDlaDefaultLicAcq::EBrowserView; |
|
502 } |
|
503 //License received silently or license storage status sent succesfully. |
|
504 else |
|
505 { |
|
506 CompleteClientRequest( aSystemError ); |
|
507 } |
|
508 } |
|
509 //Error in transaction |
|
510 else if ( iHttpStatus != HTTPStatus::EOk && |
|
511 iHttpStatus != KErrNone ) |
|
512 { |
|
513 CompleteClientRequest( KErrCommsBreak ); |
|
514 } |
|
515 //System error |
|
516 else |
|
517 { |
|
518 CompleteClientRequest( aSystemError ); |
|
519 } |
|
520 } |
|
521 |
|
522 // ---------------------------------------------------------------------------- |
|
523 // CWmDrmDlaDefaultLicAcq::CompleteClientRequest |
|
524 // ---------------------------------------------------------------------------- |
|
525 // |
|
526 void CWmDrmDlaDefaultLicAcq::CompleteClientRequest( TInt aError ) |
|
527 { |
|
528 LOGFN( "CWmDrmDlaDefaultLicAcq::CompleteClientRequest" ); |
|
529 LOG2( "aError: %d", aError ); |
|
530 if ( iClientStatus ) |
|
531 { |
|
532 User::RequestComplete( iClientStatus, aError ); |
|
533 iClientStatus = NULL; |
|
534 } |
|
535 iState = CWmDrmDlaDefaultLicAcq::ENotActive; |
|
536 } |
|
537 |
|
538 // --------------------------------------------------------------------------- |
|
539 // CWmDrmDlaDefaultLicAcq::AcquireLicenseL |
|
540 // --------------------------------------------------------------------------- |
|
541 // |
|
542 void CWmDrmDlaDefaultLicAcq::AcquireLicenseL() |
|
543 { |
|
544 LOGFN( "CWmDrmDlaDefaultLicAcq::AcquireLicenseL" ); |
|
545 // Set headers |
|
546 RArray<CWmDrmDlaDefaultHttpManager::THeader> headers; |
|
547 CleanupClosePushL( headers ); |
|
548 |
|
549 headers.AppendL( CWmDrmDlaDefaultHttpManager::THeader( HTTP::EAccept, |
|
550 KAcceptHeader8 ) ); |
|
551 headers.AppendL( |
|
552 CWmDrmDlaDefaultHttpManager::THeader( HTTP::EAcceptLanguage, |
|
553 KAcceptLanguageHeader8 ) ); |
|
554 headers.AppendL( |
|
555 CWmDrmDlaDefaultHttpManager::THeader( HTTP::EContentType, |
|
556 KPostContentTypeHeader8 ) ); |
|
557 |
|
558 // Set POST contents |
|
559 delete iFormEncoder; |
|
560 iFormEncoder = NULL; |
|
561 iFormEncoder = CHTTPFormEncoder::NewL(); |
|
562 |
|
563 //If license acquisition is non-silent, then add non-silent field to |
|
564 //request |
|
565 if ( iNonSilent ) |
|
566 { |
|
567 iFormEncoder->AddFieldL( KGetNonSilentParam8, KNonSilentValue ); |
|
568 } |
|
569 |
|
570 iFormEncoder->AddFieldL( KGetLicenseChallengeParam8, *iLicenseChallenge ); |
|
571 |
|
572 //Post a request, make sure that iLicenseResponse is NULL |
|
573 delete iLicenseResponse; |
|
574 iLicenseResponse = NULL; |
|
575 iHttpManager->Post( *iLicenseServerUrl, headers, iFormEncoder ); |
|
576 |
|
577 CleanupStack::PopAndDestroy( &headers ); |
|
578 } |
|
579 |
|
580 // --------------------------------------------------------------------------- |
|
581 // CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatusL |
|
582 // --------------------------------------------------------------------------- |
|
583 // |
|
584 void CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatusL( |
|
585 const TDesC8& aTid, |
|
586 TInt aError ) |
|
587 { |
|
588 LOGFN( "CWmDrmDlaDefaultLicAcq::SendLicenseStorageStatusL" ); |
|
589 LOG2( "aError: %d", aError ); |
|
590 TInt licenseHRESULT( MakeHRESULT( aError ) ); |
|
591 |
|
592 HBufC8* statusUrl = NULL; |
|
593 TInt pos( iLicenseServerUrl->Locate( '?' ) ); |
|
594 // If no query ('?') pos is rightmost character |
|
595 pos = (pos != KErrNotFound) ? pos : iLicenseServerUrl->Length(); |
|
596 TPtrC8 ptrUrl( iLicenseServerUrl->Left( pos ) ); |
|
597 TInt len( ptrUrl.Length() + KQueryTag8().Length() + |
|
598 KTIDHeader8().Length() + aTid.Length() ); |
|
599 |
|
600 statusUrl = HBufC8::NewLC( len ); |
|
601 TPtr8 url( statusUrl->Des() ); |
|
602 url.Append( ptrUrl ); |
|
603 url.Append( KQueryTag8 ); |
|
604 url.Append( KTIDHeader8 ); |
|
605 url.Append( aTid ); |
|
606 |
|
607 SendHRESULTL( *statusUrl, KLicenseStatusParam8(), licenseHRESULT ); |
|
608 |
|
609 CleanupStack::PopAndDestroy( statusUrl ); |
|
610 } |
|
611 |
|
612 // --------------------------------------------------------------------------- |
|
613 // CWmDrmDlaDefaultLicAcq::MakeHRESULT |
|
614 // --------------------------------------------------------------------------- |
|
615 // |
|
616 TInt CWmDrmDlaDefaultLicAcq::MakeHRESULT( |
|
617 TInt aError ) |
|
618 { |
|
619 TInt result( 0 ); |
|
620 |
|
621 LOGFNR( "CWmDrmDlaDefaultLicAcq::MakeHRESULT", result ); |
|
622 |
|
623 // If there is no error then we need to send 0x00000000 |
|
624 if ( !aError ) |
|
625 { |
|
626 result = 0; |
|
627 } |
|
628 // Convert Symbian error convert to an HRESULT |
|
629 else if ( static_cast<TUint>(aError) < KHRESULTBase ) |
|
630 { |
|
631 result = KHRESULTErrorMask | aError; |
|
632 } |
|
633 else |
|
634 { |
|
635 // This is already in HRESULT format so use it directly |
|
636 result = aError; |
|
637 } |
|
638 return result; |
|
639 } |
|
640 |
|
641 // --------------------------------------------------------------------------- |
|
642 // CWmDrmDlaDefaultLicAcq::SendHRESULTL |
|
643 // --------------------------------------------------------------------------- |
|
644 // |
|
645 void CWmDrmDlaDefaultLicAcq::SendHRESULTL( |
|
646 const TDesC8& aUrl, |
|
647 const TDesC8& aHeaderField, |
|
648 TInt aHRESULT ) |
|
649 { |
|
650 LOGFN( "CWmDrmDlaDefaultLicAcq::SendHRESULTL" ); |
|
651 |
|
652 //Set headers |
|
653 RArray<CWmDrmDlaDefaultHttpManager::THeader> headers; |
|
654 CleanupClosePushL( headers ); |
|
655 |
|
656 headers.AppendL( CWmDrmDlaDefaultHttpManager::THeader( HTTP::EAccept, |
|
657 KAcceptHeader8 ) ); |
|
658 headers.AppendL( |
|
659 CWmDrmDlaDefaultHttpManager::THeader( HTTP::EAcceptLanguage, |
|
660 KAcceptLanguageHeader8 ) ); |
|
661 headers.AppendL( |
|
662 CWmDrmDlaDefaultHttpManager::THeader( HTTP::EContentType, |
|
663 KPostContentTypeHeader8 ) ); |
|
664 |
|
665 HBufC8* resultStatus = HBufC8::NewLC( KHRESULTFormatLength ); |
|
666 resultStatus->Des().Format( KHRESULTFormat, aHRESULT ); |
|
667 |
|
668 //Set POST contents |
|
669 delete iFormEncoder; |
|
670 iFormEncoder = NULL; |
|
671 iFormEncoder = CHTTPFormEncoder::NewL(); |
|
672 |
|
673 iFormEncoder->AddFieldL( aHeaderField, *resultStatus ); |
|
674 |
|
675 CleanupStack::PopAndDestroy( resultStatus ); |
|
676 |
|
677 //Post a request |
|
678 iHttpManager->Post( aUrl, headers, iFormEncoder ); |
|
679 |
|
680 CleanupStack::PopAndDestroy( &headers ); |
|
681 } |
|
682 |
|
683 // --------------------------------------------------------------------------- |
|
684 // CWmDrmDlaDefaultLicAcq::HandleRedirectionHeadersL |
|
685 // --------------------------------------------------------------------------- |
|
686 // |
|
687 void CWmDrmDlaDefaultLicAcq::HandleRedirectionHeadersL( |
|
688 const RHTTPHeaders& aHeaders, |
|
689 const RStringPool& aStringPool ) |
|
690 { |
|
691 LOGFN( "CWmDrmDlaDefaultLicAcq::HandleRedirectionHeadersL" ); |
|
692 |
|
693 //Get the redirected location |
|
694 RStringF locationStr = aStringPool.StringF( HTTP::ELocation, |
|
695 RHTTPSession::GetTable() ); |
|
696 CleanupClosePushL( locationStr ); |
|
697 THTTPHdrVal locationValue; |
|
698 if ( !aHeaders.GetField( locationStr, 0, locationValue ) ) |
|
699 { |
|
700 //Set new redirected url and change state to redirection |
|
701 delete iLicenseServerUrl; |
|
702 iLicenseServerUrl = NULL; |
|
703 iLicenseServerUrl = locationValue.StrF().DesC().AllocL(); |
|
704 iState = CWmDrmDlaDefaultLicAcq::ERedirection; |
|
705 iHttpStatus = HTTPStatus::EOk; |
|
706 } |
|
707 else |
|
708 { |
|
709 iHttpStatus = KErrHttpRedirectNoLocationField; |
|
710 } |
|
711 CleanupStack::PopAndDestroy( &locationStr ); |
|
712 } |
|
713 |
|
714 // --------------------------------------------------------------------------- |
|
715 // CWmDrmDlaDefaultLicAcq::HandleLicenseAcquistionHeaders |
|
716 // --------------------------------------------------------------------------- |
|
717 // |
|
718 void CWmDrmDlaDefaultLicAcq::HandleLicenseAcquistionHeaders( |
|
719 const RHTTPHeaders& aHeaders, |
|
720 const RStringPool& aStringPool ) |
|
721 { |
|
722 LOGFN( "CWmDrmDlaDefaultLicAcq::HandleLicenseAcquistionHeaders" ); |
|
723 |
|
724 RStringF contentTypeNameStr = |
|
725 aStringPool.StringF( HTTP::EContentType, RHTTPSession::GetTable() ); |
|
726 |
|
727 // read the first part of content-type field |
|
728 THTTPHdrVal contentTypeVal; |
|
729 if( !aHeaders.GetField( contentTypeNameStr, 0, contentTypeVal ) ) |
|
730 { |
|
731 //Silent license acquisition |
|
732 if ( iState == CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge && |
|
733 contentTypeVal.StrF().DesC().MatchF( KDataTypeLicenseResponse ) != |
|
734 KErrNotFound ) |
|
735 { |
|
736 iHttpStatus = HTTPStatus::EOk; |
|
737 } |
|
738 //Non silent license acquisition |
|
739 else if ( iState == CWmDrmDlaDefaultLicAcq::ESendingLicenseChallenge && |
|
740 contentTypeVal.StrF().DesC().MatchF( KDataTypeHtml ) != |
|
741 KErrNotFound ) |
|
742 { |
|
743 iHttpStatus = HTTPStatus::EOk; |
|
744 iNonSilent = ETrue; |
|
745 iState = CWmDrmDlaDefaultLicAcq::ENonSilentLicenseAcquisition; |
|
746 } |
|
747 else |
|
748 { |
|
749 iHttpStatus = KErrHttpDecodeContentType; |
|
750 } |
|
751 } |
|
752 else |
|
753 { |
|
754 iHttpStatus = KErrHttpDecodeContentType; |
|
755 } |
|
756 contentTypeNameStr.Close(); |
|
757 } |
|
758 |
|
759 // --------------------------------------------------------------------------- |
|
760 // CWmDrmDlaDefaultLicAcq::LaunchBrowserViewL |
|
761 // --------------------------------------------------------------------------- |
|
762 // |
|
763 void CWmDrmDlaDefaultLicAcq::LaunchBrowserViewL() |
|
764 { |
|
765 LOGFN( "CWmDrmDlaDefaultLicAcq::LaunchBrowserViewL" ); |
|
766 |
|
767 if ( !iBrowserViewHandler ) |
|
768 { |
|
769 iBrowserViewHandler = CWmDrmDlaBrowserViewHandler::NewL(); |
|
770 } |
|
771 iBrowserViewHandler->LaunchBrowserViewL( this ); |
|
772 } |
|
773 |
|
774 // --------------------------------------------------------------------------- |
|
775 // CWmDrmDlaDefaultLicAcq::Redirection |
|
776 // --------------------------------------------------------------------------- |
|
777 // |
|
778 TInt CWmDrmDlaDefaultLicAcq::Redirection( TAny* aPtr ) |
|
779 { |
|
780 TInt err( KErrNone ); |
|
781 |
|
782 LOGFNR( "CWmDrmDlaDefaultLicAcq::Redirection", err ); |
|
783 |
|
784 CWmDrmDlaDefaultLicAcq* defaultLicAcq = |
|
785 static_cast<CWmDrmDlaDefaultLicAcq*>( aPtr ); |
|
786 |
|
787 TRAP( err, defaultLicAcq->AcquireLicenseL() ); |
|
788 if ( err ) |
|
789 { |
|
790 defaultLicAcq->CompleteClientRequest( err ); |
|
791 } |
|
792 return EFalse; |
|
793 } |
|
794 |
|
795 // --------------------------------------------------------------------------- |
|
796 // CWmDrmDlaDefaultLicAcq::PostUrlL |
|
797 // --------------------------------------------------------------------------- |
|
798 // |
|
799 const TDesC& CWmDrmDlaDefaultLicAcq::PostUrlL() |
|
800 { |
|
801 LOGFN( "CWmDrmDlaDefaultLicAcq::PostUrlL" ); |
|
802 delete iLicenseServerUrl16; |
|
803 iLicenseServerUrl16 = NULL; |
|
804 iLicenseServerUrl16 |
|
805 = EscapeUtils::ConvertToUnicodeFromUtf8L( *iLicenseServerUrl ); |
|
806 return *iLicenseServerUrl16; |
|
807 } |
|
808 |
|
809 // --------------------------------------------------------------------------- |
|
810 // CWmDrmDlaDefaultLicAcq::PostContentTypeL |
|
811 // --------------------------------------------------------------------------- |
|
812 // |
|
813 const TDesC8& CWmDrmDlaDefaultLicAcq::PostContentTypeL() |
|
814 { |
|
815 LOGFN( "CWmDrmDlaDefaultLicAcq::PostContentTypeL" ); |
|
816 return KPostContentTypeHeader8; |
|
817 } |
|
818 |
|
819 // --------------------------------------------------------------------------- |
|
820 // CWmDrmDlaDefaultLicAcq::PostDataL |
|
821 // --------------------------------------------------------------------------- |
|
822 // |
|
823 const TDesC8& CWmDrmDlaDefaultLicAcq::PostDataL() |
|
824 { |
|
825 LOGFN( "CWmDrmDlaDefaultLicAcq::PostDataL" ); |
|
826 delete iPostData; |
|
827 iPostData = NULL; |
|
828 iPostData = HBufC8::NewL( KChallenge().Length() + |
|
829 iLicenseChallenge->Length() ); |
|
830 TPtr8 ptr( iPostData->Des() ); |
|
831 ptr.Append( KChallenge() ); |
|
832 ptr.Append( *iLicenseChallenge ); |
|
833 return *iPostData; |
|
834 } |
|
835 |
|
836 // --------------------------------------------------------------------------- |
|
837 // CWmDrmDlaDefaultLicAcq::PostContentDataBoundaryL |
|
838 // --------------------------------------------------------------------------- |
|
839 // |
|
840 const TDesC8& CWmDrmDlaDefaultLicAcq::PostContentDataBoundaryL() |
|
841 { |
|
842 LOGFN( "CWmDrmDlaDefaultLicAcq::PostContentDataBoundaryL" ); |
|
843 return KAmpersand; |
|
844 } |
|
845 |
|
846 // --------------------------------------------------------------------------- |
|
847 // CWmDrmDlaDefaultLicAcq::IapId |
|
848 // --------------------------------------------------------------------------- |
|
849 // |
|
850 TInt CWmDrmDlaDefaultLicAcq::IapId() |
|
851 { |
|
852 LOGFN( "CWmDrmDlaDefaultLicAcq::IapId" ); |
|
853 return iHttpManager->IapId(); |
|
854 } |
|
855 |
|
856 // --------------------------------------------------------------------------- |
|
857 // CWmDrmDlaDefaultLicAcq::LicenseResponseReceived |
|
858 // --------------------------------------------------------------------------- |
|
859 // |
|
860 void CWmDrmDlaDefaultLicAcq::LicenseResponseReceived( |
|
861 const TDesC8& aLicenseResponse ) |
|
862 { |
|
863 TInt err( KErrNone ); |
|
864 |
|
865 LOGFNR( "CWmDrmDlaDefaultLicAcq::LicenseResponseReceived", err ); |
|
866 |
|
867 //Non-silent license response received, allocate the response and complete |
|
868 //client request |
|
869 delete iLicenseResponse; |
|
870 iLicenseResponse = NULL; |
|
871 iLicenseResponse = aLicenseResponse.Alloc(); |
|
872 if ( !iLicenseResponse ) |
|
873 { |
|
874 err = KErrNoMemory; |
|
875 } |
|
876 CompleteClientRequest( err ); |
|
877 iPlugin->UiNotifier()->SetProgress( EProcessingDRMHeader ); |
|
878 } |
|
879 |
|
880 // --------------------------------------------------------------------------- |
|
881 // CWmDrmDlaDefaultLicAcq::BrowserExit |
|
882 // --------------------------------------------------------------------------- |
|
883 // |
|
884 void CWmDrmDlaDefaultLicAcq::BrowserExit( TInt aError ) |
|
885 { |
|
886 LOGFN( "CWmDrmDlaDefaultLicAcq::BrowserExit" ); |
|
887 LOG2( "aError: %d", aError ); |
|
888 //Browser view closed in non-silent license acquisition, complete |
|
889 //client request with the error code. |
|
890 CompleteClientRequest( aError ); |
|
891 } |