|
1 /* |
|
2 * Copyright (c) 2008 - 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: rohandler wrapper for Download manager |
|
15 * |
|
16 */ |
|
17 |
|
18 #ifdef SYMBIAN_ENABLE_SPLIT_HEADERS |
|
19 #include <es_enum_partner.h> |
|
20 #endif |
|
21 #include <centralrepository.h> |
|
22 #include <cdblen.h> |
|
23 |
|
24 #ifdef __SERIES60_NATIVE_BROWSER |
|
25 #include <browseruisdkcrkeys.h> |
|
26 #endif |
|
27 |
|
28 #include <cmconnectionmethod.h> |
|
29 #include <cmdestination.h> |
|
30 #include <cmconnectionmethoddef.h> |
|
31 #include <cmmanager.h> |
|
32 |
|
33 #ifdef RD_MULTIPLE_DRIVE |
|
34 #include <driveinfo.h> |
|
35 #endif |
|
36 |
|
37 #include <data_caging_path_literals.hrh> |
|
38 |
|
39 #include <downloadmgrclient.h> |
|
40 |
|
41 #include <es_enum.h> // tconnectioninfo |
|
42 #include <es_sock.h> // rconnection rsocket |
|
43 #include <roapeng.h> |
|
44 #include <roapdef.h> |
|
45 #include <roapobserver.h> |
|
46 #include "roapsyncwrapper.h" |
|
47 |
|
48 #include "rohandlerdmgrwrapper.h" |
|
49 |
|
50 #ifdef _DEBUG |
|
51 #define DRMDEBUG( a ) RDebug::Print( a ) |
|
52 #define DRMDEBUG2( a, b ) RDebug::Print( a, b ) |
|
53 #define DRMDEBUG3( a, b, c ) RDebug::Print( a, b, c ) |
|
54 |
|
55 #define DRMDEBUGMETHOD( a ) RDebug::Print( \ |
|
56 RoHdlrDMgrWrDebugLiterals::KMethodFormat(), &( a ) ) |
|
57 // #define DRMDEBUGMETHODSTART( a ) RDebug::Print( \ |
|
58 // RoHdlrDMgrWrDebugLiterals::KMethodStartFormat(), &( a ) ) |
|
59 |
|
60 // #define DRMDEBUGMETHODFINISH( a ) RDebug::Print( \ |
|
61 // RoHdlrDMgrWrDebugLiterals::KMethodFinishFormat(), &( a ) ) |
|
62 |
|
63 // #define LOG( a ) RFileLogger::Write( \ |
|
64 // KRoLogDir(), KRoLogFile(), EFileLoggingModeAppend, a ); |
|
65 // #define LOGHEX( ptr, len ) RFileLogger::HexDump( \ |
|
66 // KRoLogDir(), KRoLogFile(), EFileLoggingModeAppend, \ |
|
67 // _S( "" ), _S( "" ), ptr, len ); |
|
68 // #define LOG2( a, b ) RFileLogger::WriteFormat( \ |
|
69 // KRoLogDir(), KRoLogFile(), EFileLoggingModeAppend, a, b ); |
|
70 |
|
71 |
|
72 namespace RoHdlrDMgrWrDebugLiterals |
|
73 { |
|
74 // Uncomment following literals if using macros LOG, LOG2 or LOGHEX anywhere |
|
75 // _LIT( KRoLogDir, "DRM" ); |
|
76 // _LIT( KRoLogFile, "RoHdlDmgrWrapper.log" ); |
|
77 |
|
78 // method Formatters ( used in macros DRMDEBUGMETHOD ) |
|
79 _LIT( KMethodFormat, "CRoHandlerDMgrWrapper::%S" ); |
|
80 |
|
81 // method Formatters ( used in macro DRMDEBUGMETHODSTART ) |
|
82 // _LIT( KMethodStartFormat, "CRoHandlerDMgrWrapper::%S -->" ); |
|
83 |
|
84 // method Formatters ( used in macro DRMDEBUGMETHODFINISH ) |
|
85 // _LIT( KMethodFinishFormat, "--> CRoHandlerDMgrWrapper::%S" ); |
|
86 |
|
87 |
|
88 _LIT( KFormatMembValInt, "%S = %d" ); |
|
89 |
|
90 //Constructors, destructor |
|
91 _LIT( KMethDestructor, "~CRoHandlerDMgrWrapper" ); |
|
92 //Methods |
|
93 _LIT( KMethConstructL, "ConstructL" ); |
|
94 _LIT( KMethNewL, "NewL" ); |
|
95 _LIT( KMethNewLC, "NewLC" ); |
|
96 _LIT( KMethDownloadAndHandleRoapTriggerL, "DownloadAndHandleRoapTriggerL" ); |
|
97 _LIT( KMethDownloadAndHandleRoapTriggerFromPrUrlL, |
|
98 "DownloadAndHandleRoapTriggerFromPrUrlL" ); |
|
99 _LIT( KMethDoDownloadAndHandleRoapTriggerL, |
|
100 "DoDownloadAndHandleRoapTriggerL" ); |
|
101 _LIT( KFormatDoDlHdlRoapTrigL, "DoDownloadAndHandleRoapTriggerL: %S" ); |
|
102 _LIT( KStrDlCreated, "download created" ); |
|
103 _LIT( KStrDlFinished, "download finished" ); |
|
104 |
|
105 _LIT( KMethSetDefaultAccessPointL, "SetDefaultAccessPointL" ); |
|
106 _LIT( KMiIapId, "iIapId" ); |
|
107 |
|
108 _LIT( KMethHandleDMgrEventL, "HandleDMgrEventL" ); |
|
109 _LIT( KFormatMethHandleDMgrEventL, "HandleDMgrEventL %S" ); |
|
110 _LIT( KStrEHttpDlCreated, "EHttpDlCreated" ); |
|
111 _LIT( KStrEHttpContentTypeReceived, "EHttpContentTypeReceived" ); |
|
112 _LIT( KStrEHttpProgDisconnected, "EHttpProgDisconnected" ); |
|
113 _LIT( KStrEHttpDlInprogress, "EHttpDlInprogress" ); |
|
114 _LIT( KStrEHttpDlCompleted, "EHttpDlCompleted" ); |
|
115 _LIT( KStrEHttpDlFailed, "EHttpDlFailed" ); |
|
116 _LIT( KStrEConnectionFailed, "EConnectionFailed" ); |
|
117 _LIT( KFormatEDlAttrErrorId, "EDlAttrErrorId = %d" ); |
|
118 |
|
119 _LIT( KMiDownLoadState, "iDownLoadState" ); |
|
120 _LIT( KMiProgressState, "iProgressState" ); |
|
121 |
|
122 } |
|
123 |
|
124 #else |
|
125 #define DRMDEBUG( a ) |
|
126 #define DRMDEBUG2( a, b ) |
|
127 #define DRMDEBUG3( a, b, c ) |
|
128 |
|
129 #define DRMDEBUGMETHOD( a ) |
|
130 //#define DRMDEBUGMETHODSTART( a ) |
|
131 //#define DRMDEBUGMETHODFINISH( a ) |
|
132 |
|
133 //#define LOG( a ) |
|
134 //#define LOGHEX( ptr, len ) |
|
135 //#define LOG2( a, b ) |
|
136 #endif |
|
137 |
|
138 #ifndef __SERIES60_NATIVE_BROWSER |
|
139 const TUid KCRUidBrowser = |
|
140 {0x10008D39}; |
|
141 const TUint32 KBrowserDefaultAccessPoint = 0x0000000E; |
|
142 const TUint32 KBrowserAccessPointSelectionMode = 0x0000001E; |
|
143 const TUint32 KBrowserNGDefaultSnapId = 0x00000053; |
|
144 #endif |
|
145 |
|
146 // CONSTANTS |
|
147 #ifndef RD_MULTIPLE_DRIVE |
|
148 _LIT( KHelperTriggerFilePath, "d:\\" ); |
|
149 #endif |
|
150 |
|
151 // ============================== LOCAL FUNCTIONS ============================== |
|
152 |
|
153 // --------------------------------------------------------------------------- |
|
154 // DoResetAndDestroy |
|
155 // Does RPointerArray< typename >->ResetAndDestroy() for the given array aPtr. |
|
156 // --------------------------------------------------------------------------- |
|
157 // |
|
158 template< typename elemType > |
|
159 LOCAL_C void DoResetAndDestroy( TAny* aPtr ) |
|
160 { |
|
161 ( reinterpret_cast< RPointerArray< elemType >* >( aPtr ) )-> |
|
162 ResetAndDestroy(); |
|
163 } |
|
164 |
|
165 // --------------------------------------------------------------------------- |
|
166 // DeleteHttpDowload |
|
167 // --------------------------------------------------------------------------- |
|
168 // |
|
169 LOCAL_C void DeleteHttpDowload( TAny* aDownload ) |
|
170 { |
|
171 reinterpret_cast< RHttpDownload* >( aDownload )->Delete(); |
|
172 } |
|
173 |
|
174 // --------------------------------------------------------------------------- |
|
175 // UpdateBufferL |
|
176 // --------------------------------------------------------------------------- |
|
177 // |
|
178 template< typename bufType, typename descType > |
|
179 LOCAL_C void UpdateBufferL( bufType*& aTargetBuf, const descType& aSourceBuf ) |
|
180 { |
|
181 if ( aTargetBuf ) |
|
182 { |
|
183 delete aTargetBuf; |
|
184 aTargetBuf = NULL; |
|
185 } |
|
186 if ( aSourceBuf.Length() ) |
|
187 { |
|
188 aTargetBuf = aSourceBuf.AllocL(); |
|
189 } |
|
190 } |
|
191 |
|
192 // --------------------------------------------------------------------------- |
|
193 // IapIdOfDefaultSnapL |
|
194 // for trapping purposes only |
|
195 // --------------------------------------------------------------------------- |
|
196 // |
|
197 LOCAL_C TUint32 IapIdOfDefaultSnapL( |
|
198 RCmManager& aCmManager, |
|
199 const TUint32 aDefaultSnap ) |
|
200 { |
|
201 RCmDestination dest( aCmManager.DestinationL( aDefaultSnap ) ); |
|
202 CleanupClosePushL( dest ); |
|
203 TUint32 iapIdOfDest( 0 ); |
|
204 |
|
205 if ( dest.ConnectionMethodCount() <= 0 ) |
|
206 { |
|
207 User::Leave( KErrNotFound ); |
|
208 } |
|
209 |
|
210 RCmConnectionMethod cMeth( dest.ConnectionMethodL( 0 ) ); |
|
211 CleanupClosePushL( cMeth ); |
|
212 |
|
213 iapIdOfDest = cMeth.GetIntAttributeL( CMManager::ECmIapId ); |
|
214 CleanupStack::PopAndDestroy( &cMeth ); |
|
215 CleanupStack::PopAndDestroy( &dest ); |
|
216 return iapIdOfDest; |
|
217 } |
|
218 |
|
219 |
|
220 // ============================= MEMBER FUNCTIONS ============================== |
|
221 |
|
222 // --------------------------------------------------------------------------- |
|
223 // CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper |
|
224 // --------------------------------------------------------------------------- |
|
225 // |
|
226 CRoHandlerDMgrWrapper::CRoHandlerDMgrWrapper() : |
|
227 CActive( CActive::EPriorityStandard ), |
|
228 iIapId( 0 ), iState( EInit ) |
|
229 { |
|
230 CActiveScheduler::Add( this ); |
|
231 } |
|
232 |
|
233 // --------------------------------------------------------------------------- |
|
234 // CRoHandlerDMgrWrapper::ConstructL |
|
235 // --------------------------------------------------------------------------- |
|
236 // |
|
237 void CRoHandlerDMgrWrapper::ConstructL() |
|
238 { |
|
239 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethConstructL() ); |
|
240 // Get UID from process |
|
241 const TInt KRoHandlerDMgrWrapperUid = 0x101F7B92; |
|
242 iDlMgr.ConnectL( TUid::Uid( KRoHandlerDMgrWrapperUid ), *this, EFalse ); |
|
243 User::LeaveIfError( iFs.Connect() ); |
|
244 User::LeaveIfError( iFs.ShareProtected() ); |
|
245 |
|
246 } |
|
247 |
|
248 // --------------------------------------------------------------------------- |
|
249 // CRoHandlerDMgrWrapper::NewL |
|
250 // --------------------------------------------------------------------------- |
|
251 // |
|
252 CRoHandlerDMgrWrapper* CRoHandlerDMgrWrapper::NewL() |
|
253 { |
|
254 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethNewL() ); |
|
255 CRoHandlerDMgrWrapper* self( CRoHandlerDMgrWrapper::NewLC() ); |
|
256 CleanupStack::Pop( self ); |
|
257 return self; |
|
258 } |
|
259 |
|
260 // --------------------------------------------------------------------------- |
|
261 // CRoHandlerDMgrWrapper::NewLC |
|
262 // --------------------------------------------------------------------------- |
|
263 // |
|
264 CRoHandlerDMgrWrapper* CRoHandlerDMgrWrapper::NewLC() |
|
265 { |
|
266 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethNewLC() ); |
|
267 CRoHandlerDMgrWrapper* self( new ( ELeave ) CRoHandlerDMgrWrapper() ); |
|
268 CleanupStack::PushL( self ); |
|
269 self->ConstructL(); |
|
270 return self; |
|
271 } |
|
272 |
|
273 // --------------------------------------------------------------------------- |
|
274 // CRoHandlerDMgrWrapper::~CRoHandlerDMgrWrapper |
|
275 // --------------------------------------------------------------------------- |
|
276 // |
|
277 CRoHandlerDMgrWrapper::~CRoHandlerDMgrWrapper() |
|
278 { |
|
279 Cancel(); |
|
280 |
|
281 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDestructor() ); |
|
282 delete iTriggerUrl; |
|
283 delete iTriggerBuf; |
|
284 delete iFileName; |
|
285 delete iRoapEng; |
|
286 |
|
287 #ifdef _DEBUG |
|
288 |
|
289 if ( iDlMgr.Handle() ) |
|
290 { |
|
291 iDlMgr.Close(); |
|
292 } |
|
293 |
|
294 #else |
|
295 |
|
296 iDlMgr.Close(); |
|
297 |
|
298 #endif |
|
299 |
|
300 iFs.Close(); |
|
301 } |
|
302 |
|
303 // --------------------------------------------------------------------------- |
|
304 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL |
|
305 // --------------------------------------------------------------------------- |
|
306 // |
|
307 void CRoHandlerDMgrWrapper::HandleRoapTriggerL( const TDesC8& aTrigger ) |
|
308 { |
|
309 if ( iState != EInit || iWait.IsStarted() ) |
|
310 { |
|
311 User::Leave( KErrNotReady ); |
|
312 } |
|
313 |
|
314 UpdateBufferL< HBufC8, TDesC8 >( iTriggerBuf, aTrigger ); |
|
315 Continue( EMeteringReportSubmit, KErrNone ); |
|
316 iWait.Start(); |
|
317 } |
|
318 |
|
319 // --------------------------------------------------------------------------- |
|
320 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL |
|
321 // --------------------------------------------------------------------------- |
|
322 // |
|
323 void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerL( const HBufC8* aUrl ) |
|
324 { |
|
325 DRMDEBUGMETHOD( |
|
326 RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerL() ); |
|
327 if ( iState != EInit || iWait.IsStarted() ) |
|
328 { |
|
329 User::Leave( KErrNotReady ); |
|
330 } |
|
331 |
|
332 UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl ); |
|
333 Continue( EGetMeteringTrigger, KErrNone ); |
|
334 iWait.Start(); |
|
335 } |
|
336 |
|
337 // --------------------------------------------------------------------------- |
|
338 // CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL |
|
339 // --------------------------------------------------------------------------- |
|
340 // |
|
341 void CRoHandlerDMgrWrapper::DownloadAndHandleRoapTriggerFromPrUrlL( |
|
342 const HBufC8* aUrl ) |
|
343 { |
|
344 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDownloadAndHandleRoapTriggerFromPrUrlL() ); |
|
345 if ( iState != EInit || iWait.IsStarted() ) |
|
346 { |
|
347 User::Leave( KErrNotReady ); |
|
348 } |
|
349 |
|
350 UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, *aUrl ); |
|
351 Continue( EGetPrUrlTrigger, KErrNone ); |
|
352 iWait.Start(); |
|
353 } |
|
354 |
|
355 // --------------------------------------------------------------------------- |
|
356 // CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL |
|
357 // --------------------------------------------------------------------------- |
|
358 // |
|
359 void CRoHandlerDMgrWrapper::DoDownloadRoapTriggerL( TMeterState aNextState ) |
|
360 { |
|
361 RFile roapTrigger; |
|
362 TBool result( EFalse ); |
|
363 TFileName triggerFileName; |
|
364 |
|
365 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethDoDownloadAndHandleRoapTriggerL() ); |
|
366 // If no Trigger URL then nothing to download. So finish transaction |
|
367 if ( !iTriggerUrl || iTriggerUrl->Length() <= 0 ) |
|
368 { |
|
369 Continue( EComplete, KErrNone ); |
|
370 return; |
|
371 } |
|
372 |
|
373 #ifndef RD_MULTIPLE_DRIVE |
|
374 |
|
375 User::LeaveIfError( roapTrigger.Temp( |
|
376 iFs, KHelperTriggerFilePath, triggerFileName, EFileWrite ) ); |
|
377 |
|
378 #else //RD_MULTIPLE_DRIVE |
|
379 _LIT( KDrive, "%c:\\" ); |
|
380 TInt driveNumber( -1 ); |
|
381 TChar driveLetter; |
|
382 DriveInfo::GetDefaultDrive( DriveInfo::EDefaultRam, driveNumber ); |
|
383 iFs.DriveToChar( driveNumber, driveLetter ); |
|
384 |
|
385 TFileName helperTriggerFilePath; |
|
386 |
|
387 helperTriggerFilePath.Format( KDrive, ( TUint )driveLetter ); |
|
388 |
|
389 User::LeaveIfError( roapTrigger.Temp( iFs, helperTriggerFilePath, |
|
390 triggerFileName, EFileWrite ) ); |
|
391 |
|
392 #endif |
|
393 UpdateBufferL< HBufC, TFileName >( iFileName, triggerFileName ); |
|
394 |
|
395 // create and start download |
|
396 RHttpDownload& download = iDlMgr.CreateDownloadL( *iTriggerUrl, result ); |
|
397 // Put download for proper cleanup. |
|
398 TCleanupItem item( DeleteHttpDowload, &download ); |
|
399 CleanupStack::PushL( item ); |
|
400 |
|
401 CleanupClosePushL( roapTrigger ); |
|
402 |
|
403 if ( result ) |
|
404 { |
|
405 DRMDEBUG2( |
|
406 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
|
407 &RoHdlrDMgrWrDebugLiterals::KStrDlCreated() ); |
|
408 iDownloadSuccess = EFalse; |
|
409 iConnectionError = EFalse; |
|
410 |
|
411 SetDefaultAccessPointL(); |
|
412 User::LeaveIfError( download.SetFileHandleAttribute( roapTrigger ) ); |
|
413 User::LeaveIfError( download.SetBoolAttribute( |
|
414 EDlAttrNoContentTypeCheck, ETrue ) ); |
|
415 User::LeaveIfError( download.Start() ); |
|
416 |
|
417 // wait until download is finished |
|
418 iState = aNextState; |
|
419 TRequestStatus* status( &iStatus ); |
|
420 *status = KRequestPending; |
|
421 SetActive(); |
|
422 } |
|
423 CleanupStack::PopAndDestroy( &roapTrigger ); |
|
424 CleanupStack::Pop( &download ); // Left open for DoSaveRoapTrigger |
|
425 } |
|
426 // --------------------------------------------------------------------------- |
|
427 // CRoHandlerDMgrWrapper::DoSaveRoapTriggerL |
|
428 // --------------------------------------------------------------------------- |
|
429 // |
|
430 void CRoHandlerDMgrWrapper::DoSaveRoapTriggerL( TMeterState aNextState ) |
|
431 { |
|
432 // Check success of download |
|
433 DRMDEBUG2( |
|
434 RoHdlrDMgrWrDebugLiterals::KFormatDoDlHdlRoapTrigL(), |
|
435 &RoHdlrDMgrWrDebugLiterals::KStrDlFinished() ); |
|
436 |
|
437 // Fetch download created in DoDownloadRoapTriggerL |
|
438 RHttpDownload* download = iDlMgr.FindDownload( *iTriggerUrl, KNullDesC8() ); |
|
439 // Delete trigger URL so that it is possible to check |
|
440 // whether or not meteringResponse has PrUrl. |
|
441 delete iTriggerUrl; |
|
442 iTriggerUrl = NULL; |
|
443 // Put download for proper cleanup. |
|
444 TCleanupItem item( DeleteHttpDowload, download ); |
|
445 CleanupStack::PushL( item ); |
|
446 RFile roapTrigger; |
|
447 |
|
448 if ( !iDownloadSuccess ) |
|
449 { |
|
450 if ( iConnectionError ) |
|
451 { |
|
452 User::Leave( KErrCouldNotConnect ); |
|
453 } |
|
454 else |
|
455 { |
|
456 User::Leave( KErrGeneral ); |
|
457 } |
|
458 } |
|
459 User::LeaveIfError( roapTrigger.Open( iFs, *iFileName, EFileShareReadersOrWriters ) ); |
|
460 CleanupClosePushL( roapTrigger ); |
|
461 // Get filehandle of ROAP trigger |
|
462 const TInt KReadBufSize = 512; |
|
463 |
|
464 RBuf8 readBuf; |
|
465 readBuf.CleanupClosePushL(); |
|
466 readBuf.CreateL( KReadBufSize ); |
|
467 |
|
468 // Read file to buffer |
|
469 TInt triggerFileSize( 0 ); |
|
470 User::LeaveIfError( roapTrigger.Size( triggerFileSize ) ); |
|
471 if ( iTriggerBuf ) |
|
472 { |
|
473 delete iTriggerBuf; |
|
474 iTriggerBuf = NULL; |
|
475 } |
|
476 iTriggerBuf = HBufC8::NewL( triggerFileSize ); |
|
477 User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) ); |
|
478 iTriggerBuf->Des().Copy( readBuf ); |
|
479 while ( readBuf.Length() == KReadBufSize ) |
|
480 { |
|
481 User::LeaveIfError( roapTrigger.Read( readBuf, KReadBufSize ) ); |
|
482 iTriggerBuf->Des().Append( readBuf ); |
|
483 } |
|
484 |
|
485 // And let ROAP handle it... |
|
486 CleanupStack::PopAndDestroy( &readBuf ); |
|
487 CleanupStack::PopAndDestroy( &roapTrigger ); |
|
488 CleanupStack::PopAndDestroy( download ); |
|
489 |
|
490 iFs.Delete( *iFileName ); |
|
491 delete iFileName; |
|
492 iFileName=NULL; |
|
493 Continue( aNextState, KErrNone ); |
|
494 } |
|
495 |
|
496 // --------------------------------------------------------------------------- |
|
497 // CRoHandlerDMgrWrapper::DoHandleRoapTriggerL |
|
498 // --------------------------------------------------------------------------- |
|
499 // |
|
500 void CRoHandlerDMgrWrapper::DoHandleRoapTriggerL( TMeterState aNextState ) |
|
501 { |
|
502 Roap::TTriggerType triggerType; |
|
503 Roap::TRiContextStatus contextStatus; |
|
504 Roap::TDomainOperation domainOperation; |
|
505 |
|
506 RPointerArray< HBufC8 > contentIds; |
|
507 |
|
508 TCleanupItem cleanup( DoResetAndDestroy< HBufC8 >, &contentIds ); |
|
509 CleanupStack::PushL( cleanup ); |
|
510 |
|
511 iRoapEng = Roap::CRoapEng::NewL(); |
|
512 |
|
513 iRoapEng->SetTriggerL( *iTriggerBuf, NULL, triggerType, contextStatus, |
|
514 domainOperation, contentIds ); |
|
515 |
|
516 CleanupStack::PopAndDestroy( &contentIds ); |
|
517 |
|
518 // if we have a valid RI context, |
|
519 // or if there is no user confirmation needed, do the ROAP |
|
520 if ( contextStatus != Roap::EInvalidContext ) |
|
521 { |
|
522 iRoapEng->AcceptL( this, &iStatus ); |
|
523 iState = aNextState; |
|
524 SetActive(); |
|
525 } |
|
526 else |
|
527 { |
|
528 Continue( EComplete, KErrCancel ); |
|
529 } |
|
530 } |
|
531 |
|
532 // --------------------------------------------------------------------------- |
|
533 // CRoHandlerDMgrWrapper::SetDefaultAccessPointL |
|
534 // --------------------------------------------------------------------------- |
|
535 // |
|
536 void CRoHandlerDMgrWrapper::SetDefaultAccessPointL() |
|
537 { |
|
538 const TInt KDestinationSelectionMode( 2 ); |
|
539 CRepository* repository( NULL ); |
|
540 TInt ap( 0 ); |
|
541 TInt alwaysAsk( 0 ); |
|
542 TUint32 iapd32( 0 ); |
|
543 TInt defaultSnap( 0 ); |
|
544 TInt err( KErrNone ); |
|
545 |
|
546 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethSetDefaultAccessPointL() ); |
|
547 |
|
548 if ( !iIapId ) |
|
549 { |
|
550 repository = CRepository::NewL( KCRUidBrowser ); |
|
551 CleanupStack::PushL( repository ); |
|
552 repository->Get( KBrowserDefaultAccessPoint, ap ); |
|
553 repository->Get( KBrowserAccessPointSelectionMode, alwaysAsk ); |
|
554 repository->Get( KBrowserNGDefaultSnapId, defaultSnap ); |
|
555 if ( ap <= KErrNotFound && defaultSnap <= KErrNotFound ) |
|
556 { |
|
557 alwaysAsk = ETrue; |
|
558 } |
|
559 else |
|
560 { |
|
561 RCmManager cmManager; |
|
562 cmManager.OpenLC(); |
|
563 if ( !alwaysAsk ) |
|
564 { |
|
565 TRAP( err, iapd32 = cmManager.GetConnectionMethodInfoIntL( |
|
566 ap, CMManager::ECmIapId ) ); |
|
567 } |
|
568 else if ( alwaysAsk == KDestinationSelectionMode ) |
|
569 { |
|
570 TRAP( err, iapd32 = IapIdOfDefaultSnapL( |
|
571 cmManager, defaultSnap ) ); |
|
572 } |
|
573 CleanupStack::PopAndDestroy( &cmManager ); |
|
574 } |
|
575 if ( !err && ( !alwaysAsk || alwaysAsk == KDestinationSelectionMode ) ) |
|
576 { |
|
577 iIapId = iapd32; |
|
578 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
|
579 &RoHdlrDMgrWrDebugLiterals::KMiIapId(), iIapId ); |
|
580 err = iDlMgr.SetIntAttribute( EDlMgrIap, iapd32 ); |
|
581 } |
|
582 CleanupStack::PopAndDestroy( repository ); |
|
583 } |
|
584 else |
|
585 { |
|
586 err = iDlMgr.SetIntAttribute( EDlMgrIap, iIapId ); |
|
587 } |
|
588 } |
|
589 |
|
590 // --------------------------------------------------------------------------- |
|
591 // CRoHandlerDMgrWrapper::Continue |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 void CRoHandlerDMgrWrapper::Continue( |
|
595 CRoHandlerDMgrWrapper::TMeterState aNextState, TInt aError ) |
|
596 { |
|
597 iState = aNextState; |
|
598 TRequestStatus* ownStatus = &iStatus; |
|
599 *ownStatus = KRequestPending; |
|
600 SetActive(); |
|
601 User::RequestComplete( ownStatus, aError ); |
|
602 } |
|
603 |
|
604 |
|
605 // MHttpDownloadMgrObserver methods |
|
606 |
|
607 // --------------------------------------------------------------------------- |
|
608 // CRoHandlerDMgrWrapper::HandleDMgrEventL |
|
609 // --------------------------------------------------------------------------- |
|
610 // |
|
611 void CRoHandlerDMgrWrapper::HandleDMgrEventL( RHttpDownload& aDownload, |
|
612 THttpDownloadEvent aEvent ) |
|
613 { |
|
614 _LIT8( KDRMHelperMimeTypeROAPTrigger, "application/vnd.oma.drm.roap-trigger+xml" ); |
|
615 |
|
616 DRMDEBUGMETHOD( RoHdlrDMgrWrDebugLiterals::KMethHandleDMgrEventL() ); |
|
617 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
|
618 &RoHdlrDMgrWrDebugLiterals::KMiDownLoadState(), aEvent.iDownloadState ); |
|
619 DRMDEBUG3( RoHdlrDMgrWrDebugLiterals::KFormatMembValInt(), |
|
620 &RoHdlrDMgrWrDebugLiterals::KMiProgressState(), aEvent.iProgressState ); |
|
621 |
|
622 if ( aEvent.iProgressState == EHttpContentTypeReceived ) |
|
623 { |
|
624 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
625 &RoHdlrDMgrWrDebugLiterals::KStrEHttpContentTypeReceived() ); |
|
626 // check received mimetype |
|
627 RBuf8 contentType; |
|
628 contentType.CleanupClosePushL(); |
|
629 contentType.CreateL( KMaxContentTypeLength ); |
|
630 User::LeaveIfError( aDownload.GetStringAttribute( EDlAttrContentType, |
|
631 contentType ) ); |
|
632 if ( !contentType.FindF( KDRMHelperMimeTypeROAPTrigger ) ) |
|
633 { |
|
634 // ROAP trigger found, continue download |
|
635 User::LeaveIfError( aDownload.Start() ); |
|
636 } |
|
637 else |
|
638 { |
|
639 // wrong MIME type?, stop download |
|
640 iDownloadSuccess = EFalse; |
|
641 User::LeaveIfError( aDownload.Delete() ); |
|
642 } |
|
643 CleanupStack::PopAndDestroy( &contentType ); |
|
644 } |
|
645 |
|
646 if ( aEvent.iDownloadState == EHttpDlCreated ) |
|
647 { |
|
648 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
649 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCreated() ); |
|
650 } |
|
651 else |
|
652 if ( aEvent.iProgressState == EHttpProgDisconnected ) |
|
653 { |
|
654 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
655 &RoHdlrDMgrWrDebugLiterals::KStrEHttpProgDisconnected() ); |
|
656 // store failure |
|
657 iDownloadSuccess = EFalse; |
|
658 iConnectionError = ETrue; |
|
659 // finished |
|
660 TRequestStatus* status( &iStatus ); |
|
661 User::RequestComplete( status, KErrCancel ); |
|
662 } |
|
663 else |
|
664 if ( aEvent.iDownloadState == EHttpDlInprogress ) |
|
665 { |
|
666 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
667 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlInprogress() ); |
|
668 } |
|
669 else |
|
670 if ( aEvent.iDownloadState == EHttpDlCompleted ) |
|
671 { |
|
672 // store success |
|
673 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
674 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlCompleted() ); |
|
675 iDownloadSuccess = ETrue; |
|
676 |
|
677 // finished |
|
678 TRequestStatus* status( &iStatus ); |
|
679 User::RequestComplete( status, KErrNone ); |
|
680 } |
|
681 else |
|
682 if ( aEvent.iDownloadState == EHttpDlFailed ) |
|
683 { |
|
684 TInt32 err; |
|
685 |
|
686 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
687 &RoHdlrDMgrWrDebugLiterals::KStrEHttpDlFailed() ); |
|
688 // store failure |
|
689 iDownloadSuccess = EFalse; |
|
690 User::LeaveIfError( aDownload.GetIntAttribute( |
|
691 EDlAttrErrorId, err ) ); |
|
692 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatEDlAttrErrorId(), err ); |
|
693 |
|
694 if ( err == EConnectionFailed || err |
|
695 == ETransactionFailed ) |
|
696 { |
|
697 DRMDEBUG2( RoHdlrDMgrWrDebugLiterals::KFormatMethHandleDMgrEventL(), |
|
698 &RoHdlrDMgrWrDebugLiterals::KStrEConnectionFailed() ); |
|
699 iConnectionError = ETrue; |
|
700 } |
|
701 |
|
702 // finished |
|
703 TRequestStatus* status( &iStatus ); |
|
704 User::RequestComplete( status, KErrCancel ); |
|
705 } |
|
706 } |
|
707 |
|
708 |
|
709 // RoapObserver methods |
|
710 |
|
711 // --------------------------------------------------------------------------- |
|
712 // CRoHandlerDMgrWrapper::PostResponseUrlL |
|
713 // --------------------------------------------------------------------------- |
|
714 // |
|
715 void CRoHandlerDMgrWrapper::PostResponseUrlL( const TDesC8& aPostResponseUrl ) |
|
716 { |
|
717 UpdateBufferL< HBufC8, TDesC8 >( iTriggerUrl, aPostResponseUrl ); |
|
718 |
|
719 if ( !iIapId ) |
|
720 { |
|
721 // Take AP from open conenction |
|
722 RSocketServ socketServer; |
|
723 |
|
724 TInt err( KErrNone ); |
|
725 |
|
726 err = socketServer.Connect(); |
|
727 |
|
728 RConnection myConnection; |
|
729 |
|
730 err = myConnection.Open( socketServer ); |
|
731 |
|
732 TUint connectionCount( 0 ); |
|
733 |
|
734 err = myConnection.EnumerateConnections( connectionCount ); |
|
735 |
|
736 if ( err != KErrNone || connectionCount < 1 ) |
|
737 { |
|
738 return; |
|
739 } |
|
740 |
|
741 TPckgBuf<TConnectionInfoV2> connectionInfo; |
|
742 |
|
743 err = myConnection.GetConnectionInfo( connectionCount, |
|
744 connectionInfo ); |
|
745 |
|
746 iIapId = connectionInfo().iIapId; |
|
747 |
|
748 myConnection.Close(); |
|
749 socketServer.Close(); |
|
750 } |
|
751 } |
|
752 |
|
753 // Trivial RoapObserver methods |
|
754 TBool CRoHandlerDMgrWrapper::ConnectionConfL() |
|
755 { |
|
756 return ETrue; |
|
757 } |
|
758 |
|
759 TBool CRoHandlerDMgrWrapper::ContactRiConfL() |
|
760 { |
|
761 return ETrue; |
|
762 } |
|
763 |
|
764 TBool CRoHandlerDMgrWrapper::TransIdConfL() |
|
765 { |
|
766 return EFalse; |
|
767 } |
|
768 |
|
769 void CRoHandlerDMgrWrapper::RightsObjectDetailsL( |
|
770 const RPointerArray<CDRMRights>& /*aRightsList*/ ) |
|
771 { |
|
772 // do nothing |
|
773 } |
|
774 |
|
775 void CRoHandlerDMgrWrapper::ContentDownloadInfoL( TPath& /*aTempFolder*/, |
|
776 TFileName& /*aContentName*/, TInt& aMaxSize ) |
|
777 { |
|
778 aMaxSize = -1; |
|
779 } |
|
780 |
|
781 void CRoHandlerDMgrWrapper::ContentDetailsL( const TDesC& /*aPath*/, |
|
782 const TDesC8& /*aType*/, const TUid& /*aAppUid*/ ) |
|
783 { |
|
784 } |
|
785 |
|
786 void CRoHandlerDMgrWrapper::RoapProgressInfoL( const TInt /*aProgressInfo*/ ) |
|
787 { |
|
788 // do nothing |
|
789 } |
|
790 |
|
791 void CRoHandlerDMgrWrapper::ErrorUrlL( const TDesC8& /*aErrorUrl*/ ) |
|
792 { |
|
793 // do nothing |
|
794 } |
|
795 |
|
796 |
|
797 |
|
798 // CActive methods |
|
799 |
|
800 // --------------------------------------------------------------------------- |
|
801 // CRoHandlerDMgrWrapper::DoCancel |
|
802 // --------------------------------------------------------------------------- |
|
803 // |
|
804 void CRoHandlerDMgrWrapper::DoCancel() |
|
805 { |
|
806 delete iRoapEng; |
|
807 iRoapEng = NULL; |
|
808 if ( iWait.IsStarted() ) |
|
809 { |
|
810 iWait.AsyncStop(); |
|
811 } |
|
812 } |
|
813 |
|
814 // --------------------------------------------------------------------------- |
|
815 // CRoHandlerDMgrWrapper::RunL |
|
816 // --------------------------------------------------------------------------- |
|
817 // |
|
818 void CRoHandlerDMgrWrapper::RunL() |
|
819 { |
|
820 User::LeaveIfError( iStatus.Int() ); |
|
821 switch ( iState ) |
|
822 { |
|
823 //case EInit: |
|
824 case EGetMeteringTrigger: |
|
825 { |
|
826 DoDownloadRoapTriggerL( ESaveMeteringTrigger ); |
|
827 } |
|
828 break; |
|
829 case ESaveMeteringTrigger: |
|
830 { |
|
831 DoSaveRoapTriggerL( EMeteringReportSubmit ); |
|
832 } |
|
833 break; |
|
834 |
|
835 case EMeteringReportSubmit: |
|
836 { |
|
837 DoHandleRoapTriggerL( EGetPrUrlTrigger ); |
|
838 } |
|
839 break; |
|
840 case EGetPrUrlTrigger: |
|
841 { |
|
842 delete iRoapEng; |
|
843 iRoapEng = NULL; |
|
844 DoDownloadRoapTriggerL( ESavePrUrlTrigger ); |
|
845 } |
|
846 break; |
|
847 case ESavePrUrlTrigger: |
|
848 { |
|
849 DoSaveRoapTriggerL( EPrRoapRequest ); |
|
850 } |
|
851 break; |
|
852 case EPrRoapRequest: |
|
853 { |
|
854 DoHandleRoapTriggerL( EComplete ); |
|
855 } |
|
856 break; |
|
857 case EComplete: |
|
858 { |
|
859 delete iRoapEng; |
|
860 iRoapEng = NULL; |
|
861 iWait.AsyncStop(); |
|
862 } |
|
863 break; |
|
864 |
|
865 default: |
|
866 User::Leave( KErrNotSupported ); |
|
867 } |
|
868 } |
|
869 |
|
870 // --------------------------------------------------------------------------- |
|
871 // CRoHandlerDMgrWrapper::RunError |
|
872 // --------------------------------------------------------------------------- |
|
873 // |
|
874 TInt CRoHandlerDMgrWrapper::RunError( TInt /* aError */ ) |
|
875 { |
|
876 //_LIT( KCatchedError, "Catched error" ); |
|
877 //User::Panic( KCatchedError, aError ); |
|
878 if ( iWait.IsStarted() ) |
|
879 { |
|
880 iWait.AsyncStop(); |
|
881 } |
|
882 return KErrNone; |
|
883 } |