|
1 /* |
|
2 * Copyright (c) 2004 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 the License "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * This file contains the declaration of the Client interface of Download Mgr Server. |
|
16 * |
|
17 */ |
|
18 |
|
19 |
|
20 // INCLUDE FILES |
|
21 #include "DownloadMgrLogger.h" |
|
22 #include "DownloadMgrClient.h" |
|
23 #include "DownloadMgrServer.h" |
|
24 #include "DownloadMgrStart.h" |
|
25 #include "DownloadMgrDef.h" |
|
26 #include "DownloadMgrDefAttrib.h" |
|
27 #include "DownloadMgrHandler.h" |
|
28 #include <e32svr.h> |
|
29 #include <EscapeUtils.h> |
|
30 #include <centralrepository.h> |
|
31 #include "DownloadMgrCRKeys.h" |
|
32 #include <BrowserUiSDKCRKeys.h> |
|
33 #include <CodDownload.h> |
|
34 |
|
35 // CONSTANTS |
|
36 const TInt KHttpDownloadMgrObserverArrayGranularity = 4; |
|
37 const TInt KHttpDownloadMgrDefalutAttribsGranularity = 4; |
|
38 const TInt KDefaultMsgSlots = 16; |
|
39 |
|
40 _LIT8( KHttpScheme, "http" ); |
|
41 _LIT8( KHttpsScheme, "https" ); |
|
42 |
|
43 // GLOBAL FUNCTIONS |
|
44 #if defined(_DEBUG) |
|
45 void DMPanic( TInt aPanicCode ) |
|
46 { |
|
47 User::Panic( _L("DownloadManager"), aPanicCode ); |
|
48 } |
|
49 #endif |
|
50 |
|
51 // ================= MEMBER FUNCTIONS ======================= |
|
52 |
|
53 /** |
|
54 * Extension class. |
|
55 */ |
|
56 NONSHARABLE_CLASS( CRHttpDownloadMgrExtension ) : public CBase |
|
57 { |
|
58 public: // Constructors and destructor |
|
59 |
|
60 /** |
|
61 * Two-phased constructor. |
|
62 */ |
|
63 static CRHttpDownloadMgrExtension* NewL(); |
|
64 |
|
65 /** |
|
66 * Destructor. |
|
67 */ |
|
68 virtual ~CRHttpDownloadMgrExtension(); |
|
69 |
|
70 /* |
|
71 * Next uri observer setter function |
|
72 */ |
|
73 void SetNextUriObserver( MHttpDownloadMgrNextUriObserver* aObserver ); |
|
74 |
|
75 /* |
|
76 * Next uri observer getter function |
|
77 */ |
|
78 MHttpDownloadMgrNextUriObserver* NextUriObserver() const; |
|
79 |
|
80 |
|
81 protected: // Constructors |
|
82 |
|
83 /** |
|
84 * C++ default constructor. |
|
85 */ |
|
86 CRHttpDownloadMgrExtension(); |
|
87 |
|
88 /** |
|
89 * By default Symbian 2nd phase constructor is private. |
|
90 */ |
|
91 void ConstructL(); |
|
92 |
|
93 public: |
|
94 |
|
95 static TInt GetRepositoryValue( TUint32 aSettingId, TInt& aSettingValue ); |
|
96 |
|
97 static TInt SetRepositoryValue( TUint32 aSettingId, TInt aSettingValue ); |
|
98 |
|
99 public: // Data |
|
100 TInt iEventBroadcastLevel; |
|
101 |
|
102 MHttpDownloadMgrNextUriObserver* iNextUriObserver; ///< Not Owned. |
|
103 |
|
104 TInt iSessionId; |
|
105 |
|
106 TInt iAdjustEventPriorityFlag; |
|
107 }; |
|
108 |
|
109 // ================= MEMBER FUNCTIONS ======================= |
|
110 |
|
111 // ----------------------------------------------------------------------------- |
|
112 // CRHttpDownloadMgrExtension::CRHttpDownloadMgrExtension |
|
113 // ----------------------------------------------------------------------------- |
|
114 // |
|
115 CRHttpDownloadMgrExtension::CRHttpDownloadMgrExtension() |
|
116 :iEventBroadcastLevel( 0 ) |
|
117 ,iAdjustEventPriorityFlag( 0 ) |
|
118 { |
|
119 iNextUriObserver = NULL; |
|
120 } |
|
121 |
|
122 // ----------------------------------------------------------------------------- |
|
123 // CRHttpDownloadMgrExtension::ConstructL |
|
124 // ----------------------------------------------------------------------------- |
|
125 // |
|
126 void CRHttpDownloadMgrExtension::ConstructL() |
|
127 { |
|
128 CLOG_ENTERFN("CRHttpDownloadMgrExtension::ConstructL"); |
|
129 } |
|
130 |
|
131 // ----------------------------------------------------------------------------- |
|
132 // CRHttpDownloadMgrExtension::NewL |
|
133 // ----------------------------------------------------------------------------- |
|
134 // |
|
135 CRHttpDownloadMgrExtension* CRHttpDownloadMgrExtension::NewL() |
|
136 { |
|
137 CRHttpDownloadMgrExtension* self = new(ELeave)CRHttpDownloadMgrExtension(); |
|
138 CleanupStack::PushL( self ); |
|
139 self->ConstructL(); |
|
140 CleanupStack::Pop(); |
|
141 return self; |
|
142 } |
|
143 |
|
144 // Destructor |
|
145 CRHttpDownloadMgrExtension::~CRHttpDownloadMgrExtension() |
|
146 { |
|
147 CLOG_ENTERFN("CRHttpDownloadMgrExtension::~CRHttpDownloadMgrExtension"); |
|
148 } |
|
149 |
|
150 // ----------------------------------------------------------------------------- |
|
151 // CRHttpDownloadMgrExtension::SetNextUriObserver |
|
152 // ----------------------------------------------------------------------------- |
|
153 // |
|
154 void CRHttpDownloadMgrExtension::SetNextUriObserver( MHttpDownloadMgrNextUriObserver* aObserver ) |
|
155 { |
|
156 iNextUriObserver = aObserver; |
|
157 } |
|
158 |
|
159 // ----------------------------------------------------------------------------- |
|
160 // CRHttpDownloadMgrExtension::NextUriObserver |
|
161 // ----------------------------------------------------------------------------- |
|
162 // |
|
163 MHttpDownloadMgrNextUriObserver* CRHttpDownloadMgrExtension::NextUriObserver() const |
|
164 { |
|
165 return iNextUriObserver; |
|
166 } |
|
167 |
|
168 |
|
169 // ----------------------------------------------------------------------------- |
|
170 // CRHttpDownloadMgrExtension::GetRepositoryValue |
|
171 // ----------------------------------------------------------------------------- |
|
172 // |
|
173 TInt CRHttpDownloadMgrExtension::GetRepositoryValue( TUint32 aSettingId, TInt& aSettingValue ) |
|
174 { |
|
175 aSettingValue = KErrNotFound; |
|
176 CRepository* rep = NULL; |
|
177 |
|
178 TRAPD( err, rep = CRepository::NewL( KCRUidBrowserUiLV ) ); |
|
179 if( (err == KErrNone) && rep ) |
|
180 { |
|
181 err = rep->Get( aSettingId, aSettingValue ); |
|
182 } |
|
183 delete rep; |
|
184 return err; |
|
185 } |
|
186 |
|
187 // ----------------------------------------------------------------------------- |
|
188 // CRHttpDownloadMgrExtension::SetRepositoryValue |
|
189 // ----------------------------------------------------------------------------- |
|
190 // |
|
191 TInt CRHttpDownloadMgrExtension::SetRepositoryValue( TUint32 aSettingId, TInt aSettingValue ) |
|
192 { |
|
193 CRepository* rep = NULL; |
|
194 |
|
195 TRAPD( err, rep = CRepository::NewL( KCRUidBrowserUiLV ) ); |
|
196 if( (err == KErrNone) && rep ) |
|
197 { |
|
198 err = rep->Set( aSettingId, aSettingValue ); |
|
199 } |
|
200 delete rep; |
|
201 return err; |
|
202 } |
|
203 |
|
204 // --------------------------------------------------------- |
|
205 // RHttpDownloadMgr::RHttpDownloadMgr |
|
206 // --------------------------------------------------------- |
|
207 // |
|
208 EXPORT_C RHttpDownloadMgr::RHttpDownloadMgr() |
|
209 { |
|
210 // Reset data members as R-objects are not zero'd. |
|
211 iAppUid = TUid::Null(); |
|
212 iDownloadArray = NULL; |
|
213 iObservers = NULL; |
|
214 iDefaultAttribs = NULL; |
|
215 iManagerHandler = NULL; |
|
216 iExtension = NULL; |
|
217 } |
|
218 |
|
219 // --------------------------------------------------------- |
|
220 // RHttpDownloadMgr::ConnectL |
|
221 // --------------------------------------------------------- |
|
222 // |
|
223 EXPORT_C void RHttpDownloadMgr::ConnectL( TUid aAppUid, |
|
224 MHttpDownloadMgrObserver& aObserver, |
|
225 TBool aMaster ) |
|
226 { |
|
227 CLOG_CREATE; |
|
228 |
|
229 __ASSERT_DEBUG( !Handle(), DMPanic( KErrAlreadyExists ) ); |
|
230 |
|
231 TRAPD( err, DoConnectL( aAppUid, aObserver, aMaster ) ); |
|
232 if( err ) |
|
233 { |
|
234 Close(); |
|
235 User::Leave( err ); |
|
236 } |
|
237 } |
|
238 |
|
239 // --------------------------------------------------------- |
|
240 // RHttpDownloadMgr::DoConnectL |
|
241 // --------------------------------------------------------- |
|
242 // |
|
243 void RHttpDownloadMgr::DoConnectL( TUid aAppUid, |
|
244 MHttpDownloadMgrObserver& aObserver, |
|
245 TBool aMaster ) |
|
246 { |
|
247 CLOG_ENTERFN( "RHttpDownloadMgr::ConnectL" ); |
|
248 |
|
249 TInt error = KErrNone; |
|
250 RProcess server; |
|
251 error = server.Create( KDownloadMgrServerExe, TPtr( NULL, 0 ), |
|
252 TUidType( KNullUid, KNullUid, KUidDownloadMgrSrvExe ) ); |
|
253 CLOG_WRITE_FORMAT( "RHttpDownloadMgr::ConnectL after process creation, err %d", error ); |
|
254 |
|
255 if( !error ) |
|
256 { |
|
257 TRequestStatus status; |
|
258 server.Rendezvous( status ); |
|
259 if( status != KRequestPending ) |
|
260 { |
|
261 CLOG_WRITE( "RHttpDownloadMgr::ConnectL pending status error." ); |
|
262 server.Kill( 0 ); |
|
263 } |
|
264 else |
|
265 { |
|
266 CLOG_WRITE( "RHttpDownloadMgr::ConnectL pending resume server." ); |
|
267 server.Resume( ); |
|
268 } |
|
269 User::WaitForRequest( status ); |
|
270 error = ( server.ExitType() == EExitPanic ) ? KErrGeneral : status.Int(); |
|
271 server.Close(); |
|
272 } |
|
273 User::LeaveIfError( error ); |
|
274 CLOG_WRITE( "Creating..." ); |
|
275 User::LeaveIfError( CreateSession( KDownloadMgrServerName, Version(), KDefaultMsgSlots ) ); |
|
276 CLOG_WRITE( "Created" ); |
|
277 |
|
278 CLOG_WRITE( "Starting initialization" ); |
|
279 InitializeL( aAppUid, aObserver, aMaster ); |
|
280 CLOG_WRITE( "Init OK" ); |
|
281 } |
|
282 |
|
283 // --------------------------------------------------------- |
|
284 // RHttpDownloadMgr::InitializeL |
|
285 // --------------------------------------------------------- |
|
286 // |
|
287 void RHttpDownloadMgr::InitializeL( TUid aAppUid, |
|
288 MHttpDownloadMgrObserver& aObserver, |
|
289 TBool aMaster ) |
|
290 { |
|
291 CLOG_ENTERFN( "RHttpDownloadMgr::InitializeL" ) |
|
292 |
|
293 iAppUid = aAppUid; |
|
294 AddObserverL( aObserver ); |
|
295 iExtension = CRHttpDownloadMgrExtension::NewL(); |
|
296 CLOG_ATTACH( iExtension, this ); |
|
297 iDownloadArray = new (ELeave) CArrayPtrFlat< RHttpDownload >( 1 ); |
|
298 if( aMaster ) |
|
299 { |
|
300 iManagerHandler = new (ELeave) CDownloadMgrHandler ( this ); |
|
301 CLOG_ATTACH( iManagerHandler, this ); |
|
302 iManagerHandler->StartL(); |
|
303 } |
|
304 |
|
305 TPckg<TUid> uidPckg( iAppUid ); |
|
306 TInt count( 0 ); |
|
307 TPckg<TInt> pckgCount( count ); |
|
308 TPckg<TInt> sessionId( iExtension->iSessionId ); |
|
309 // 0st param - application UID |
|
310 // 1st param - the amount of downloads at server side belongs to the same UID |
|
311 // 2st param - master flag |
|
312 // 3rd param - session id |
|
313 |
|
314 User::LeaveIfError( SendReceive( EHttpDownloadMgrInitialize, |
|
315 TIpcArgs( &uidPckg, &pckgCount, aMaster, |
|
316 &sessionId ) ) ); |
|
317 |
|
318 CLOG_NAME_2( _L("Session_%x_%x"), aAppUid.iUid, iExtension->iSessionId ); |
|
319 |
|
320 CLOG_WRITE_FORMAT( "count: %d", count ) |
|
321 // There are downloads at server side which needs to be attached |
|
322 if( count ) |
|
323 { |
|
324 // Create a buffer which will contain the handles. |
|
325 TPckgBuf<TInt> arrayPckg; |
|
326 HBufC8* buf = HBufC8::NewLC( count*arrayPckg.Size() ); |
|
327 // Get the handles from the server |
|
328 TPtr8 ptr = buf->Des(); |
|
329 AttachL( ptr ); |
|
330 // Create subsessions one by one. |
|
331 for( TInt i = 0; i < count; i++ ) |
|
332 { |
|
333 RHttpDownload* download = new (ELeave) RHttpDownload ( this ); |
|
334 CleanupStack::PushL( download ); |
|
335 // Parse the handle from the buffer. |
|
336 arrayPckg.Copy( buf->Mid( i*arrayPckg.Size(), arrayPckg.Size() ) ); |
|
337 // Attach subsession to the server by the handle. |
|
338 download->AttachL( arrayPckg() ); |
|
339 TBool isCodDownload ( EFalse ); |
|
340 download->GetBoolAttribute ( EDlAttrCodDownload , isCodDownload ); |
|
341 if( isCodDownload ) |
|
342 { |
|
343 //paused Download |
|
344 download->InitPausedCodDownloadL( iAppUid ); |
|
345 |
|
346 // Update CodData in Download Mgr Server |
|
347 HBufC8* mediaInfo8 = NULL; |
|
348 mediaInfo8 = download->iCodDownload->UpdatedDownloadDataL(); |
|
349 if (mediaInfo8) |
|
350 { |
|
351 download->SetDownloadDataAttribute(*mediaInfo8); |
|
352 delete mediaInfo8; |
|
353 |
|
354 // Buffer attributes in CRHttpDownloadExtension class |
|
355 download->BufferAttributesL(); |
|
356 } |
|
357 User::LeaveIfError( download->GetProductDownloadedSize( ) ); |
|
358 } |
|
359 AddToArrayL( download ); |
|
360 CleanupStack::Pop( download ); //download |
|
361 } |
|
362 |
|
363 CleanupStack::PopAndDestroy( buf ); // buf |
|
364 } |
|
365 } |
|
366 |
|
367 // --------------------------------------------------------- |
|
368 // RHttpDownloadMgr::AttachL |
|
369 // --------------------------------------------------------- |
|
370 // |
|
371 void RHttpDownloadMgr::AttachL( TDes8& aBuf ) |
|
372 { |
|
373 CLOG_ENTERFN( "RHttpDownloadMgr::AttachL" ) |
|
374 // 0st param - buffer will contain handles. |
|
375 // The handles idetifies the download subsessions. |
|
376 |
|
377 User::LeaveIfError( SendReceive( EHttpDownloadMgrAttach, |
|
378 TIpcArgs( &aBuf ) ) ); |
|
379 } |
|
380 |
|
381 // --------------------------------------------------------- |
|
382 // RHttpDownloadMgr::CloseDownload |
|
383 // --------------------------------------------------------- |
|
384 // |
|
385 void RHttpDownloadMgr::CloseDownload( RHttpDownload* aElement ) |
|
386 { |
|
387 CLOG_ENTERFN( "RHttpDownloadMgr::CloseDownload" ); |
|
388 |
|
389 // As this class owns the array of subsessions, this role is |
|
390 // to close them. |
|
391 RemoveFromArray( aElement ); |
|
392 aElement->Close(); |
|
393 delete aElement; |
|
394 aElement = NULL; |
|
395 } |
|
396 |
|
397 // --------------------------------------------------------- |
|
398 // RHttpDownloadMgr::Version |
|
399 // --------------------------------------------------------- |
|
400 // |
|
401 EXPORT_C TVersion RHttpDownloadMgr::Version( void ) const |
|
402 { |
|
403 return TVersion( KDownloadMgrMajorVersionNumber, |
|
404 KDownloadMgrMinorVersionNumber, |
|
405 KDownloadMgrBuildVersionNumber ); |
|
406 } |
|
407 |
|
408 |
|
409 // --------------------------------------------------------- |
|
410 // RHttpDownloadMgr::Close |
|
411 // --------------------------------------------------------- |
|
412 // |
|
413 EXPORT_C void RHttpDownloadMgr::Close() |
|
414 { |
|
415 |
|
416 if( !Handle() ) |
|
417 { |
|
418 return; |
|
419 } |
|
420 |
|
421 CLOG_WRITE( "RHttpDownloadMgr::Close" ) |
|
422 if( iDownloadArray ) |
|
423 { |
|
424 TInt count = iDownloadArray->Count(); |
|
425 while( count-- ) |
|
426 { |
|
427 CLOG_WRITE_FORMAT( "Close download count[%d]", count ); |
|
428 RHttpDownload* download = (*iDownloadArray)[count]; |
|
429 CloseDownload( download ); |
|
430 } |
|
431 iDownloadArray->Reset(); |
|
432 delete iDownloadArray; |
|
433 iDownloadArray = NULL; |
|
434 } |
|
435 |
|
436 if( iExtension ) |
|
437 { |
|
438 delete iExtension; |
|
439 iExtension = NULL; |
|
440 } |
|
441 |
|
442 if( iObservers ) |
|
443 { |
|
444 iObservers->Reset(); |
|
445 delete iObservers; |
|
446 iObservers = NULL; |
|
447 } |
|
448 |
|
449 if( iDefaultAttribs ) |
|
450 { |
|
451 iDefaultAttribs->ResetAndDestroy(); |
|
452 delete iDefaultAttribs; |
|
453 iDefaultAttribs = NULL; |
|
454 } |
|
455 |
|
456 if( iManagerHandler ) |
|
457 { |
|
458 iManagerHandler->Cancel(); |
|
459 delete iManagerHandler; |
|
460 iManagerHandler = NULL; |
|
461 } |
|
462 |
|
463 RHandleBase::Close(); |
|
464 |
|
465 CLOG_CLOSE; |
|
466 } |
|
467 |
|
468 // --------------------------------------------------------- |
|
469 // RHttpDownloadMgr::AddObserverL |
|
470 // --------------------------------------------------------- |
|
471 // |
|
472 EXPORT_C void RHttpDownloadMgr::AddObserverL( MHttpDownloadMgrObserver& aObserver ) |
|
473 { |
|
474 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
475 |
|
476 CLOG_ENTERFN( "RHttpDownloadMgr::AddObserverL" ) |
|
477 |
|
478 if ( iObservers == NULL ) |
|
479 { |
|
480 iObservers = new (ELeave) CDownloadMgrObserver( |
|
481 KHttpDownloadMgrObserverArrayGranularity ); |
|
482 } |
|
483 |
|
484 TInt index( 0 ); |
|
485 if ( FindObserver( aObserver, index ) == KErrNone ) |
|
486 { |
|
487 // Observer already added. |
|
488 } |
|
489 else |
|
490 { |
|
491 iObservers->AppendL( &aObserver ); |
|
492 } |
|
493 } |
|
494 |
|
495 // --------------------------------------------------------- |
|
496 // RHttpDownloadMgr::RemoveObserver |
|
497 // --------------------------------------------------------- |
|
498 // |
|
499 EXPORT_C void RHttpDownloadMgr::RemoveObserver( MHttpDownloadMgrObserver& aObserver ) |
|
500 { |
|
501 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
502 |
|
503 CLOG_ENTERFN( "RHttpDownloadMgr::RemoveObserver" ) |
|
504 |
|
505 if ( iObservers ) |
|
506 { |
|
507 TInt index( 0 ); |
|
508 if ( FindObserver( aObserver, index ) != KErrNone ) |
|
509 { |
|
510 // Observer not found. Do nothing. |
|
511 } |
|
512 else |
|
513 { |
|
514 // Observer found. |
|
515 iObservers->Delete( index ); |
|
516 // Free up memory. |
|
517 if ( iObservers->Count() == 0 ) |
|
518 { |
|
519 delete iObservers; |
|
520 iObservers = NULL; |
|
521 } |
|
522 } |
|
523 } |
|
524 } |
|
525 |
|
526 // --------------------------------------------------------- |
|
527 // RHttpDownloadMgr::FindObserver |
|
528 // --------------------------------------------------------- |
|
529 // |
|
530 TInt RHttpDownloadMgr::FindObserver( MHttpDownloadMgrObserver& aObserver, TInt& aIndex ) const |
|
531 { |
|
532 CLOG_ENTERFN( "RHttpDownloadMgr::FindObserver" ) |
|
533 |
|
534 TInt ret( KErrNotFound ); |
|
535 |
|
536 if ( iObservers == NULL ) |
|
537 { |
|
538 ret = KErrNotFound; |
|
539 } |
|
540 else |
|
541 { |
|
542 MHttpDownloadMgrObserver* obs = &aObserver; |
|
543 TKeyArrayFix key( 0, ECmpTUint32 ); // Compare pointers |
|
544 ret = iObservers->Find( obs, key, aIndex ); |
|
545 } |
|
546 |
|
547 return ret; |
|
548 } |
|
549 |
|
550 // --------------------------------------------------------- |
|
551 // RHttpDownloadMgr::CurrentDownloads |
|
552 // --------------------------------------------------------- |
|
553 // |
|
554 EXPORT_C const CDownloadArray& RHttpDownloadMgr::CurrentDownloads() const |
|
555 { |
|
556 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
557 |
|
558 CLOG_WRITE_FORMAT( "RHttpDownloadMgr::CurrentDownloads %d", iDownloadArray->Count() ) |
|
559 return *iDownloadArray; |
|
560 } |
|
561 |
|
562 // --------------------------------------------------------- |
|
563 // RHttpDownloadMgr::CreateDownloadL |
|
564 // --------------------------------------------------------- |
|
565 // |
|
566 EXPORT_C RHttpDownload& RHttpDownloadMgr::CreateDownloadL( const TDesC8& aUrl, |
|
567 TBool& aResult ) |
|
568 { |
|
569 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
570 |
|
571 CLOG_ENTERFN( "RHttpDownloadMgr::CreateDownloadL" ) |
|
572 RHttpDownload* download = DoFindDownloadL( aUrl, KNullDesC8 ); |
|
573 |
|
574 if( !download ) |
|
575 { |
|
576 // there is no ongoing download with this URL |
|
577 // create one and add to the array |
|
578 aResult = ETrue; |
|
579 return CreateDownloadL( aUrl ); |
|
580 } |
|
581 else |
|
582 { |
|
583 // we already have a download, just return a reference to it. |
|
584 aResult = EFalse; |
|
585 return *download; |
|
586 } |
|
587 } |
|
588 |
|
589 // --------------------------------------------------------- |
|
590 // RHttpDownloadMgr::CreateDownloadL |
|
591 // --------------------------------------------------------- |
|
592 // |
|
593 EXPORT_C RHttpDownload& RHttpDownloadMgr::CreateDownloadL( const TDesC8& aUrl ) |
|
594 { |
|
595 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
596 |
|
597 CLOG_ENTERFN( "RHttpDownloadMgr::CreateDownloadL" ) |
|
598 |
|
599 RHttpDownload* download = new (ELeave) RHttpDownload ( this ); |
|
600 CleanupStack::PushL( download ); |
|
601 CleanupClosePushL( *download ); |
|
602 HBufC8* buf = PackedDefaultAttributesLC(); |
|
603 download->CreateL( aUrl, buf->Des() ); |
|
604 RHttpDownload& item = AddToArrayL( download ); |
|
605 CleanupStack::PopAndDestroy( buf ); // buf |
|
606 CleanupStack::Pop( 2 ); // download->Close, download |
|
607 |
|
608 return item; |
|
609 } |
|
610 |
|
611 // --------------------------------------------------------- |
|
612 // RHttpDownloadMgr::CreateCodDownloadL |
|
613 // --------------------------------------------------------- |
|
614 // |
|
615 EXPORT_C RHttpDownload& RHttpDownloadMgr::CreateCodDownloadL( const TDesC8& aUrl, |
|
616 const TDesC8& aBuf, |
|
617 const TDesC8& aMimeType, |
|
618 CEikonEnv* aEikEnv, |
|
619 TBool& aResult ) |
|
620 { |
|
621 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
622 |
|
623 CLOG_ENTERFN( "RHttpDownloadMgr::CreateCodDownloadL" ) |
|
624 |
|
625 RHttpDownload& download = CreateDownloadL( aUrl, aResult ); |
|
626 download.InitCodDownloadL( aBuf, aMimeType, aEikEnv ); |
|
627 download.SetBoolAttribute( EDlAttrCodDownload, ETrue ); |
|
628 |
|
629 return download; |
|
630 } |
|
631 |
|
632 // --------------------------------------------------------- |
|
633 // RHttpDownloadMgr::CreateClientSideDownloadL |
|
634 // --------------------------------------------------------- |
|
635 // |
|
636 EXPORT_C RHttpDownload& RHttpDownloadMgr::CreateClientSideDownloadL( |
|
637 TInt aHttpTransaction,TBool& aResult ) |
|
638 { |
|
639 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
640 |
|
641 RHTTPTransaction* httpTransaction = |
|
642 REINTERPRET_CAST( RHTTPTransaction* , aHttpTransaction ); |
|
643 RHttpDownload& download = |
|
644 CreateDownloadL( httpTransaction->Request().URI().UriDes() ); |
|
645 |
|
646 download.SetBoolAttribute( EDlAttrContinue, ETrue ); |
|
647 download.SetHttpTransactionL( aHttpTransaction ); |
|
648 |
|
649 // Set the disconnect notification |
|
650 httpTransaction->PropertySet().SetPropertyL |
|
651 ( |
|
652 httpTransaction->Session().StringPool().StringF( HTTP::ENotifyOnDisconnect, RHTTPSession::GetTable() ), |
|
653 httpTransaction->Session().StringPool().StringF( HTTP::EEnableDisconnectNotification, RHTTPSession::GetTable() ) |
|
654 ); |
|
655 |
|
656 aResult = ETrue; // download is created |
|
657 |
|
658 return download; |
|
659 } |
|
660 |
|
661 // --------------------------------------------------------- |
|
662 // RHttpDownloadMgr::FindDownload |
|
663 // --------------------------------------------------------- |
|
664 // |
|
665 EXPORT_C RHttpDownload* RHttpDownloadMgr::FindDownload( const TDesC8& aUrl, |
|
666 const TDesC8& aMsgBody ) |
|
667 { |
|
668 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
669 |
|
670 CLOG_ENTERFN( "RHttpDownloadMgr::FindDownload" ) |
|
671 RHttpDownload* retVal = NULL; |
|
672 |
|
673 TRAP_IGNORE( retVal = DoFindDownloadL( aUrl, aMsgBody) ); |
|
674 |
|
675 return retVal; |
|
676 } |
|
677 |
|
678 // --------------------------------------------------------- |
|
679 // RHttpDownloadMgr::DownloadFromHandleL |
|
680 // --------------------------------------------------------- |
|
681 // |
|
682 RHttpDownload& RHttpDownloadMgr::DownloadFromHandleL( TUint aHandle ) |
|
683 { |
|
684 CLOG_ENTERFN( "RHttpDownloadMgr::DownloadFromHandleL" ) |
|
685 // Check the download's handle in the array |
|
686 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
687 { |
|
688 if( (*iDownloadArray)[i]->IsDownload( aHandle ) ) |
|
689 { |
|
690 return *(*iDownloadArray)[i]; |
|
691 } |
|
692 } |
|
693 User::Leave( KErrNotFound ); |
|
694 |
|
695 // Just let the compiler be satisfied |
|
696 return *(*iDownloadArray)[iDownloadArray->Count()]; |
|
697 } |
|
698 |
|
699 // --------------------------------------------------------- |
|
700 // RHttpDownloadMgr::AddToArrayL |
|
701 // --------------------------------------------------------- |
|
702 // |
|
703 RHttpDownload& RHttpDownloadMgr::AddToArrayL( RHttpDownload* aElement ) |
|
704 { |
|
705 CLOG_ENTERFN( "RHttpDownloadMgr::AddToArrayL" ); |
|
706 |
|
707 TInt index( 0 ); |
|
708 TInt err = FindInArray( aElement, index ); |
|
709 if ( !err ) |
|
710 { |
|
711 // Already added. Do nothing, just return a reference to the |
|
712 // element in the array. |
|
713 } |
|
714 else |
|
715 { |
|
716 TInt count = iDownloadArray->Count(); |
|
717 // 'count' will be the index of the new appended element: |
|
718 index = count; |
|
719 iDownloadArray->AppendL( aElement ); |
|
720 } |
|
721 |
|
722 return *(*iDownloadArray)[index]; |
|
723 } |
|
724 |
|
725 // --------------------------------------------------------- |
|
726 // RHttpDownloadMgr::RemoveFromArray |
|
727 // --------------------------------------------------------- |
|
728 // |
|
729 void RHttpDownloadMgr::RemoveFromArray( RHttpDownload* aElement ) |
|
730 { |
|
731 CLOG_ENTERFN( "RHttpDownloadMgr::RemoveFromArray" ) |
|
732 |
|
733 TInt index( 0 ); |
|
734 TInt err = FindInArray( aElement, index ); |
|
735 if ( !err ) |
|
736 { |
|
737 // Found. Remove from array: |
|
738 iDownloadArray->Delete( index ); |
|
739 iDownloadArray->Compress(); |
|
740 } |
|
741 } |
|
742 |
|
743 // --------------------------------------------------------- |
|
744 // RHttpDownloadMgr::FindInArray |
|
745 // --------------------------------------------------------- |
|
746 // |
|
747 TInt RHttpDownloadMgr::FindInArray( RHttpDownload* aElement, TInt& aIndex ) const |
|
748 { |
|
749 CLOG_ENTERFN( "RHttpDownloadMgr::FindInArray" ); |
|
750 |
|
751 //__ASSERT_DEBUG( iDownloadArray, Panic...) |
|
752 TKeyArrayFix key( 0, ECmpTUint32 ); // Compare pointers |
|
753 TInt ret = iDownloadArray->Find( aElement, key, aIndex ); |
|
754 |
|
755 return ret; |
|
756 } |
|
757 |
|
758 // --------------------------------------------------------- |
|
759 // RHttpDownloadMgr::PauseAll |
|
760 // --------------------------------------------------------- |
|
761 // |
|
762 EXPORT_C TInt RHttpDownloadMgr::PauseAll() |
|
763 { |
|
764 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
765 |
|
766 CLOG_ENTERFN( "RHttpDownloadMgr::PauseAll" ) |
|
767 |
|
768 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
769 { |
|
770 (*iDownloadArray)[i]->Pause(); |
|
771 } |
|
772 |
|
773 return KErrNone; |
|
774 } |
|
775 |
|
776 // --------------------------------------------------------- |
|
777 // RHttpDownloadMgr::StartAll |
|
778 // --------------------------------------------------------- |
|
779 // |
|
780 EXPORT_C TInt RHttpDownloadMgr::StartAll() |
|
781 { |
|
782 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
783 |
|
784 CLOG_ENTERFN( "RHttpDownloadMgr::StartAllL" ) |
|
785 |
|
786 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
787 { |
|
788 (*iDownloadArray)[i]->Start(); |
|
789 } |
|
790 |
|
791 return KErrNone; |
|
792 } |
|
793 |
|
794 // --------------------------------------------------------- |
|
795 // RHttpDownloadMgr::ResetAll |
|
796 // --------------------------------------------------------- |
|
797 // |
|
798 EXPORT_C TInt RHttpDownloadMgr::ResetAll() |
|
799 { |
|
800 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
801 |
|
802 CLOG_ENTERFN( "RHttpDownloadMgr::ResetAll" ) |
|
803 |
|
804 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
805 { |
|
806 (*iDownloadArray)[i]->Reset(); |
|
807 } |
|
808 |
|
809 return KErrNone; |
|
810 } |
|
811 |
|
812 // --------------------------------------------------------- |
|
813 // RHttpDownloadMgr::DeleteAll |
|
814 // --------------------------------------------------------- |
|
815 // |
|
816 EXPORT_C TInt RHttpDownloadMgr::DeleteAll() |
|
817 { |
|
818 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
819 |
|
820 CLOG_ENTERFN( "RHttpDownloadMgr::DeleteAll" ) |
|
821 |
|
822 TInt err( KErrNone ); |
|
823 |
|
824 TInt i = iDownloadArray->Count(); |
|
825 while( i ) |
|
826 { |
|
827 TInt temp = (*iDownloadArray)[0]->Delete(); |
|
828 if( temp ) |
|
829 { |
|
830 err = temp; |
|
831 } |
|
832 --i; |
|
833 } |
|
834 |
|
835 return err; |
|
836 } |
|
837 |
|
838 // --------------------------------------------------------- |
|
839 // RHttpDownloadMgr::Disconnect |
|
840 // --------------------------------------------------------- |
|
841 // |
|
842 EXPORT_C TInt RHttpDownloadMgr::Disconnect() |
|
843 { |
|
844 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
845 |
|
846 CLOG_ENTERFN( "RHttpDownloadMgr::Disconnect" ) |
|
847 |
|
848 // First pause all downloads. |
|
849 // It'd be difficult to pause client side downloads from |
|
850 // server side. |
|
851 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
852 { |
|
853 (*iDownloadArray)[i]->Pause(); |
|
854 } |
|
855 |
|
856 return SendReceive( EHttpDownloadMgrDisconnect, TIpcArgs() ); |
|
857 } |
|
858 |
|
859 // --------------------------------------------------------- |
|
860 // RHttpDownloadMgr::GetIntAttribute |
|
861 // --------------------------------------------------------- |
|
862 // |
|
863 EXPORT_C TInt RHttpDownloadMgr::GetIntAttribute( const TUint aAttribute, |
|
864 TInt32& aValue ) |
|
865 { |
|
866 switch ( aAttribute ) |
|
867 { |
|
868 case EDlMgrHasActiveDownloads: |
|
869 { |
|
870 return CRHttpDownloadMgrExtension::GetRepositoryValue( KDownloadMgrHasActiveDownloads, (TInt&)aValue ); |
|
871 } |
|
872 case EDlMgrAutoAcceptCod: |
|
873 { |
|
874 return CRHttpDownloadMgrExtension::GetRepositoryValue( KDownloadMgrAutoAcceptCod, (TInt&)aValue ); |
|
875 } |
|
876 case EDlMgrNumOfClientSideDownload: |
|
877 { |
|
878 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
879 return NumberOfClientSideDownload( aValue ); |
|
880 } |
|
881 default: |
|
882 { |
|
883 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
884 TPckg<TInt32> pckg( aValue ); |
|
885 return SendReceive( EHttpDownloadMgrGetIntAttribute, |
|
886 TIpcArgs( aAttribute, &pckg ) ); |
|
887 } |
|
888 } |
|
889 } |
|
890 |
|
891 // --------------------------------------------------------- |
|
892 // RHttpDownloadMgr::NumberOfClientSideDownload |
|
893 // --------------------------------------------------------- |
|
894 // |
|
895 TInt RHttpDownloadMgr::NumberOfClientSideDownload( TInt32& aValue ) |
|
896 { |
|
897 TInt err( KErrNone ); |
|
898 |
|
899 aValue = 0; |
|
900 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
901 { |
|
902 if( (*iDownloadArray)[i]->IsClientSideDownload() ) |
|
903 { |
|
904 aValue++; |
|
905 } |
|
906 } |
|
907 |
|
908 return err; |
|
909 } |
|
910 |
|
911 // --------------------------------------------------------- |
|
912 // RHttpDownloadMgr::GetBoolAttribute |
|
913 // --------------------------------------------------------- |
|
914 // |
|
915 EXPORT_C TInt RHttpDownloadMgr::GetBoolAttribute( const TUint aAttribute, |
|
916 TBool& aValue ) |
|
917 { |
|
918 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
919 |
|
920 CLOG_ENTERFN( "RHttpDownloadMgr::GetIntAttribute" ) |
|
921 |
|
922 TPckg<TBool> pckg( aValue ); |
|
923 |
|
924 return SendReceive( EHttpDownloadMgrGetBoolAttribute, |
|
925 TIpcArgs( aAttribute, &pckg ) ); |
|
926 } |
|
927 |
|
928 // --------------------------------------------------------- |
|
929 // RHttpDownloadMgr::GetStringAttributeL |
|
930 // --------------------------------------------------------- |
|
931 // |
|
932 EXPORT_C TInt RHttpDownloadMgr::GetStringAttribute( const TUint aAttribute, |
|
933 TDes16& aValue ) |
|
934 { |
|
935 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
936 |
|
937 CLOG_ENTERFN( "RHttpDownloadMgr::GetIntAttribute" ) |
|
938 |
|
939 return SendReceive( EHttpDownloadMgrGetStringAttribute, |
|
940 TIpcArgs( aAttribute, &aValue ) ); |
|
941 } |
|
942 |
|
943 // --------------------------------------------------------- |
|
944 // RHttpDownloadMgr::GetStringAttribute |
|
945 // --------------------------------------------------------- |
|
946 // |
|
947 EXPORT_C TInt RHttpDownloadMgr::GetStringAttribute( const TUint aAttribute, |
|
948 TDes8& aValue ) |
|
949 { |
|
950 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
951 |
|
952 CLOG_ENTERFN( "RHttpDownloadMgr::GetIntAttribute" ) |
|
953 |
|
954 return SendReceive( EHttpDownloadMgrGetString8Attribute, |
|
955 TIpcArgs( aAttribute, &aValue ) ); |
|
956 } |
|
957 |
|
958 // --------------------------------------------------------- |
|
959 // RHttpDownloadMgr::SetIntAttributeL |
|
960 // --------------------------------------------------------- |
|
961 // |
|
962 EXPORT_C TInt RHttpDownloadMgr::SetIntAttribute( const TUint aAttribute, |
|
963 TInt32 aValue ) |
|
964 { |
|
965 if( aAttribute == EDlMgrHasActiveDownloads ) |
|
966 { |
|
967 return CRHttpDownloadMgrExtension::SetRepositoryValue( |
|
968 KDownloadMgrHasActiveDownloads, (TInt&)aValue ); |
|
969 } |
|
970 else |
|
971 { |
|
972 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
973 return SendReceive( EHttpDownloadMgrSetIntAttribute, |
|
974 TIpcArgs( aAttribute, aValue ) ); |
|
975 } |
|
976 } |
|
977 |
|
978 // --------------------------------------------------------- |
|
979 // RHttpDownloadMgr::SetBoolAttributeL |
|
980 // --------------------------------------------------------- |
|
981 // |
|
982 EXPORT_C TInt RHttpDownloadMgr::SetBoolAttribute( const TUint aAttribute, |
|
983 TBool aValue ) |
|
984 { |
|
985 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
986 |
|
987 CLOG_ENTERFN( "RHttpDownloadMgr::SetBoolAttributeL" ) |
|
988 |
|
989 return SendReceive( EHttpDownloadMgrSetBoolAttribute, |
|
990 TIpcArgs( aAttribute, aValue ) ); |
|
991 } |
|
992 |
|
993 // --------------------------------------------------------- |
|
994 // RHttpDownloadMgr::SetStringAttributeL |
|
995 // --------------------------------------------------------- |
|
996 // |
|
997 EXPORT_C TInt RHttpDownloadMgr::SetStringAttribute( const TUint aAttribute, |
|
998 const TDesC16& aValue ) |
|
999 { |
|
1000 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1001 |
|
1002 CLOG_ENTERFN( "RHttpDownloadMgr::SetStringAttributeL" ) |
|
1003 |
|
1004 return SendReceive( EHttpDownloadMgrSetStringAttribute, |
|
1005 TIpcArgs( aAttribute, &aValue ) ); |
|
1006 } |
|
1007 |
|
1008 // --------------------------------------------------------- |
|
1009 // RHttpDownloadMgr::SetStringAttribute |
|
1010 // --------------------------------------------------------- |
|
1011 // |
|
1012 EXPORT_C TInt RHttpDownloadMgr::SetStringAttribute( const TUint aAttribute, |
|
1013 const TDesC8& aValue ) |
|
1014 { |
|
1015 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1016 |
|
1017 CLOG_ENTERFN( "RHttpDownloadMgr::SetStringAttributeL" ) |
|
1018 |
|
1019 return SendReceive( EHttpDownloadMgrSetString8Attribute, |
|
1020 TIpcArgs( aAttribute, &aValue ) ); |
|
1021 } |
|
1022 |
|
1023 // --------------------------------------------------------- |
|
1024 // RHttpDownloadMgr::SetDefaultIntAttribute |
|
1025 // --------------------------------------------------------- |
|
1026 // |
|
1027 EXPORT_C TInt RHttpDownloadMgr::SetDefaultIntAttribute( const TUint aAttribute, |
|
1028 TInt32 aValue ) |
|
1029 { |
|
1030 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1031 |
|
1032 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultIntAttributeL" ) |
|
1033 |
|
1034 TRAPD( err, DoSetDefaultAttributeL( aAttribute, aValue ) ); |
|
1035 |
|
1036 return err; |
|
1037 } |
|
1038 |
|
1039 // --------------------------------------------------------- |
|
1040 // RHttpDownloadMgr::SetDefaultBoolAttribute |
|
1041 // --------------------------------------------------------- |
|
1042 // |
|
1043 EXPORT_C TInt RHttpDownloadMgr::SetDefaultBoolAttribute( const TUint aAttribute, |
|
1044 TBool aValue ) |
|
1045 { |
|
1046 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1047 |
|
1048 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1049 |
|
1050 TRAPD( err, DoSetDefaultAttributeL( aAttribute, aValue ) ); |
|
1051 |
|
1052 return err; |
|
1053 } |
|
1054 |
|
1055 // --------------------------------------------------------- |
|
1056 // RHttpDownloadMgr::SetDefaultStringAttribute |
|
1057 // --------------------------------------------------------- |
|
1058 // |
|
1059 EXPORT_C TInt RHttpDownloadMgr::SetDefaultStringAttribute( const TUint aAttribute, |
|
1060 const TDesC16& aValue ) |
|
1061 { |
|
1062 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1063 |
|
1064 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1065 |
|
1066 TRAPD( err, DoSetDefaultAttributeL( aAttribute, aValue ) ); |
|
1067 |
|
1068 return err; |
|
1069 } |
|
1070 |
|
1071 // --------------------------------------------------------- |
|
1072 // RHttpDownloadMgr::SetDefaultStringAttribute |
|
1073 // --------------------------------------------------------- |
|
1074 // |
|
1075 EXPORT_C TInt RHttpDownloadMgr::SetDefaultStringAttribute( const TUint aAttribute, |
|
1076 const TDesC8& aValue ) |
|
1077 { |
|
1078 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1079 |
|
1080 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1081 |
|
1082 TRAPD( err, DoSetDefaultAttributeL( aAttribute, aValue ) ); |
|
1083 |
|
1084 return err; |
|
1085 } |
|
1086 |
|
1087 // --------------------------------------------------------- |
|
1088 // RHttpDownloadMgr::SetNextUriObserver |
|
1089 // --------------------------------------------------------- |
|
1090 // |
|
1091 EXPORT_C void RHttpDownloadMgr::SetNextUriObserver( MHttpDownloadMgrNextUriObserver* aObserver ) |
|
1092 { |
|
1093 __ASSERT_DEBUG( Handle(), DMPanic( KErrDisconnected ) ); |
|
1094 |
|
1095 iExtension->SetNextUriObserver( aObserver ); |
|
1096 } |
|
1097 |
|
1098 // --------------------------------------------------------- |
|
1099 // RHttpDownloadMgr::NextUriObserver |
|
1100 // --------------------------------------------------------- |
|
1101 // |
|
1102 MHttpDownloadMgrNextUriObserver* RHttpDownloadMgr::NextUriObserver() const |
|
1103 { |
|
1104 return iExtension->iNextUriObserver; |
|
1105 } |
|
1106 |
|
1107 // --------------------------------------------------------- |
|
1108 // RHttpDownloadMgr::SessionId |
|
1109 // --------------------------------------------------------- |
|
1110 // |
|
1111 TInt RHttpDownloadMgr::SessionId() const |
|
1112 { |
|
1113 return iExtension->iSessionId; |
|
1114 } |
|
1115 |
|
1116 // --------------------------------------------------------- |
|
1117 // RHttpDownloadMgr::DoSetStringAttributeL |
|
1118 // --------------------------------------------------------- |
|
1119 // |
|
1120 void RHttpDownloadMgr::DoSetDefaultAttributeL( const TUint aAttribute, |
|
1121 TBool aValue ) |
|
1122 { |
|
1123 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1124 |
|
1125 if( iDefaultAttribs == NULL ) |
|
1126 { |
|
1127 iDefaultAttribs = new (ELeave) CArrayPtrFlat< CDefaultAttrib >( |
|
1128 KHttpDownloadMgrDefalutAttribsGranularity ); |
|
1129 } |
|
1130 CDefaultAttrib* attrib = CDefaultAttrib::NewL( (THttpDownloadAttrib)aAttribute, |
|
1131 aValue ); |
|
1132 iDefaultAttribs->AppendL( attrib ); |
|
1133 } |
|
1134 |
|
1135 // --------------------------------------------------------- |
|
1136 // RHttpDownloadMgr::DoSetStringAttributeL |
|
1137 // --------------------------------------------------------- |
|
1138 // |
|
1139 void RHttpDownloadMgr::DoSetDefaultAttributeL( const TUint aAttribute, |
|
1140 TInt32 aValue ) |
|
1141 { |
|
1142 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1143 |
|
1144 if( iDefaultAttribs == NULL ) |
|
1145 { |
|
1146 iDefaultAttribs = new (ELeave) CArrayPtrFlat< CDefaultAttrib >( |
|
1147 KHttpDownloadMgrDefalutAttribsGranularity ); |
|
1148 } |
|
1149 CDefaultAttrib* attrib = CDefaultAttrib::NewL( (THttpDownloadAttrib)aAttribute, |
|
1150 aValue ); |
|
1151 iDefaultAttribs->AppendL( attrib ); |
|
1152 } |
|
1153 |
|
1154 // --------------------------------------------------------- |
|
1155 // RHttpDownloadMgr::DoSetStringAttributeL |
|
1156 // --------------------------------------------------------- |
|
1157 // |
|
1158 void RHttpDownloadMgr::DoSetDefaultAttributeL( const TUint aAttribute, |
|
1159 const TDesC8& aValue ) |
|
1160 { |
|
1161 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1162 |
|
1163 if( iDefaultAttribs == NULL ) |
|
1164 { |
|
1165 iDefaultAttribs = new (ELeave) CArrayPtrFlat< CDefaultAttrib >( |
|
1166 KHttpDownloadMgrDefalutAttribsGranularity ); |
|
1167 } |
|
1168 CDefaultAttrib* attrib = CDefaultAttrib::NewL( (THttpDownloadAttrib)aAttribute, |
|
1169 aValue ); |
|
1170 iDefaultAttribs->AppendL( attrib ); |
|
1171 } |
|
1172 |
|
1173 // --------------------------------------------------------- |
|
1174 // RHttpDownloadMgr::DoSetStringAttributeL |
|
1175 // --------------------------------------------------------- |
|
1176 // |
|
1177 void RHttpDownloadMgr::DoSetDefaultAttributeL( const TUint aAttribute, |
|
1178 const TDesC16& aValue ) |
|
1179 { |
|
1180 CLOG_ENTERFN( "RHttpDownloadMgr::SetDefaultBoolAttribute" ) |
|
1181 |
|
1182 if( iDefaultAttribs == NULL ) |
|
1183 { |
|
1184 iDefaultAttribs = new (ELeave) CArrayPtrFlat< CDefaultAttrib >( |
|
1185 KHttpDownloadMgrDefalutAttribsGranularity ); |
|
1186 } |
|
1187 CDefaultAttrib* attrib = CDefaultAttrib::NewL( (THttpDownloadAttrib)aAttribute, |
|
1188 aValue ); |
|
1189 iDefaultAttribs->AppendL( attrib ); |
|
1190 } |
|
1191 |
|
1192 // --------------------------------------------------------- |
|
1193 // RHttpDownloadMgr::HandleDMgrEventL |
|
1194 // --------------------------------------------------------- |
|
1195 // |
|
1196 |
|
1197 void RHttpDownloadMgr::HandleDMgrEventL( RHttpDownload& aDownload, |
|
1198 THttpDownloadEvent aEvent ) |
|
1199 { |
|
1200 CLOG_ENTERFN( "RHttpDownloadMgr::HandleDMgrEventL" ) |
|
1201 iExtension->iEventBroadcastLevel++; |
|
1202 CLOG_WRITE_FORMAT( "aDownload = %x", &aDownload ); |
|
1203 CLOG_WRITE_FORMAT( "Inc iEventBroadcastLevel = %d", iExtension->iEventBroadcastLevel ); |
|
1204 // In case of EHttpDlDeleted getting most of the attributes are forbidden, |
|
1205 // because the engine is most likely is not ready to serve! Some of the |
|
1206 // attributes are buffered in client side. |
|
1207 aDownload.SetEventType( aEvent.iDownloadState ); |
|
1208 |
|
1209 if( (( EHttpDlInprogress == aEvent.iDownloadState ) && ( EHttpProgCodDescriptorDownloaded == aEvent.iProgressState ))|| |
|
1210 (( EHttpDlInprogress == aEvent.iDownloadState ) && ( EHttpProgCodDownloadShouldResume == aEvent.iProgressState ))|| |
|
1211 (( EHttpDlPaused == aEvent.iDownloadState ) && ( EHttpProgCodDescriptorDownloaded == aEvent.iProgressState )) |
|
1212 ) |
|
1213 { |
|
1214 TBool isCod( ETrue ); |
|
1215 |
|
1216 if(EHttpProgCodDownloadShouldResume == aEvent.iProgressState) |
|
1217 { |
|
1218 //resume only for apps with non-zero uid. otherwise the resume will happen from music player which sets the appuid as zero. |
|
1219 TInt32 clientAppUid(0); |
|
1220 GetIntAttribute(EDlMgrAppUid , clientAppUid); |
|
1221 if( !clientAppUid ) |
|
1222 { |
|
1223 iExtension->iEventBroadcastLevel--; |
|
1224 return; |
|
1225 } |
|
1226 } |
|
1227 |
|
1228 else |
|
1229 { |
|
1230 TRAPD( err, isCod = aDownload.CheckContentTypeAndCreateCodDownloadL() ); |
|
1231 if( isCod ) |
|
1232 { |
|
1233 if( err ) |
|
1234 { |
|
1235 // The error code is processed by the server |
|
1236 aDownload.SetOnError( err ); |
|
1237 iExtension->iEventBroadcastLevel--; |
|
1238 return; |
|
1239 } |
|
1240 } |
|
1241 |
|
1242 } |
|
1243 TRAPD( err, aDownload.DoStartCodL() ); |
|
1244 if( err ) |
|
1245 { |
|
1246 aDownload.SetOnError( err ); |
|
1247 iExtension->iEventBroadcastLevel--; |
|
1248 return; |
|
1249 } |
|
1250 |
|
1251 } |
|
1252 else if( EHttpDlCancelTransaction == aEvent.iDownloadState ) |
|
1253 { |
|
1254 aDownload.DeleteTransaction(); |
|
1255 } |
|
1256 |
|
1257 else if( EHttpProgCodDownloadPause == aEvent.iProgressState ) |
|
1258 { |
|
1259 if(aDownload.iCodDownload) |
|
1260 { |
|
1261 aDownload.iCodDownload->Pause(); |
|
1262 } |
|
1263 } |
|
1264 else if( EHttpDlProgProgressive == aEvent.iProgressState ) |
|
1265 { |
|
1266 if(aDownload.iCodDownload) |
|
1267 { |
|
1268 aDownload.iCodDownload->SetCodDlAttached(ETrue); |
|
1269 } |
|
1270 } |
|
1271 else if( EHttpDlProgNonProgressive == aEvent.iProgressState ) |
|
1272 { |
|
1273 if(aDownload.iCodDownload) |
|
1274 { |
|
1275 aDownload.iCodDownload->SetCodDlAttached(EFalse); |
|
1276 } |
|
1277 } |
|
1278 |
|
1279 // TODO: make sure that all COD test cases works OK |
|
1280 |
|
1281 // ...and close the download. |
|
1282 if( EHttpDlDeleted == aEvent.iDownloadState ) |
|
1283 { |
|
1284 CloseDownload( &aDownload ); |
|
1285 } |
|
1286 |
|
1287 iExtension->iEventBroadcastLevel--; |
|
1288 |
|
1289 // When a download completes, close the subsession to make a message slot free. |
|
1290 // Also the required information will be cached before closing the subsession |
|
1291 if( EHttpDlMultipleMOCompleted == aEvent.iDownloadState && |
|
1292 ( |
|
1293 EHttpProgContentFileMoved == aEvent.iProgressState || |
|
1294 EHttpProgContentFileMovedAndDestFNChanged == aEvent.iProgressState |
|
1295 ) |
|
1296 ) |
|
1297 { |
|
1298 //Store all the info clinet side in RHttpDownload's extension API |
|
1299 aDownload.SaveDownloadInfoL(); |
|
1300 //Close the subsession to free up the message slot |
|
1301 aDownload.CloseSubSession(); |
|
1302 } |
|
1303 TInt count = iObservers->Count(); |
|
1304 for( TInt i = 0; i < count; i++ ) |
|
1305 { |
|
1306 CLOG_WRITE_FORMAT( "HandleDMgrEventL( aDownload = 0x%x)", this ); |
|
1307 TRAP_IGNORE( (*iObservers)[i]->HandleDMgrEventL( aDownload, aEvent ) ); |
|
1308 if(!iObservers)break; |
|
1309 |
|
1310 } |
|
1311 |
|
1312 //CLOG_WRITE_FORMAT( "Dec iEventBroadcastLevel = %d", iExtension->iEventBroadcastLevel ); |
|
1313 } |
|
1314 |
|
1315 // --------------------------------------------------------- |
|
1316 // RHttpDownloadMgr::BroadcastEvent |
|
1317 // --------------------------------------------------------- |
|
1318 // |
|
1319 void RHttpDownloadMgr::BroadcastEvent( RHttpDownload& aDownload, |
|
1320 THttpDownloadEvent aEvent ) |
|
1321 { |
|
1322 CLOG_WRITE_3( "BroadcastEvent: dl [%x], DownloadState [%d], ProgressState [%d]", this, aEvent.iDownloadState, aEvent.iProgressState ); |
|
1323 for( TInt i = 0; i < iObservers->Count(); i++ ) |
|
1324 { |
|
1325 TRAP_IGNORE( (*iObservers)[i]->HandleDMgrEventL( aDownload, aEvent ) ); |
|
1326 // The download shouldn't be deleted in nested loops!!! |
|
1327 if( 1 == iExtension->iEventBroadcastLevel ) |
|
1328 { |
|
1329 if( aDownload.IsToBeDeleted() ) |
|
1330 { |
|
1331 // Decremented before delete because we check the |
|
1332 // value in aDownload.Delete(); |
|
1333 iExtension->iEventBroadcastLevel--; |
|
1334 CLOG_WRITE_FORMAT( "Dec iEventBroadcastLevel = %d", iExtension->iEventBroadcastLevel ); |
|
1335 aDownload.Delete(); |
|
1336 iExtension->iEventBroadcastLevel++; |
|
1337 return; |
|
1338 } |
|
1339 } |
|
1340 } |
|
1341 } |
|
1342 |
|
1343 // --------------------------------------------------------- |
|
1344 // RHttpDownloadMgr::HandleSessionEventL |
|
1345 // --------------------------------------------------------- |
|
1346 // |
|
1347 void RHttpDownloadMgr::HandleSessionEventL( TInt aHandle, THttpDownloadEvent aEvent ) |
|
1348 { |
|
1349 TRAP_IGNORE( DoHandleSessionEventL( aHandle, aEvent ) ); |
|
1350 } |
|
1351 |
|
1352 // --------------------------------------------------------- |
|
1353 // RHttpDownloadMgr::DoHandleSessionEventL |
|
1354 // --------------------------------------------------------- |
|
1355 // |
|
1356 void RHttpDownloadMgr::DoHandleSessionEventL( TInt aHandle, THttpDownloadEvent aEvent ) |
|
1357 { |
|
1358 RHttpDownload* download = new (ELeave) RHttpDownload ( this ); |
|
1359 CleanupStack::PushL( download ); |
|
1360 CleanupClosePushL( *download ); |
|
1361 // Attach subsession to the server by the handle. |
|
1362 download->AttachL( aHandle ); |
|
1363 AddToArrayL( download ); |
|
1364 CleanupStack::Pop( download ); //download |
|
1365 // Forward the event to the client |
|
1366 HandleDMgrEventL( *download, aEvent ); |
|
1367 } |
|
1368 |
|
1369 // --------------------------------------------------------- |
|
1370 // RHttpDownloadMgr::StartSessionEventNotification |
|
1371 // --------------------------------------------------------- |
|
1372 // |
|
1373 void RHttpDownloadMgr::StartSessionEventNotification( const TDesC8& aDownloadState, |
|
1374 const TDesC8& aProgressState, |
|
1375 const TDesC8& aHandle, |
|
1376 TRequestStatus& aStatus ) |
|
1377 { |
|
1378 CLOG_ENTERFN( "RHttpDownload::StartSessionEventNotification" ) |
|
1379 |
|
1380 SendReceive( EHttpDownloadMgrSessionEventSubscription, |
|
1381 TIpcArgs( &aDownloadState, &aProgressState, &aHandle ), |
|
1382 aStatus ); |
|
1383 } |
|
1384 |
|
1385 // --------------------------------------------------------- |
|
1386 // RHttpDownloadMgr::CancelSessionEventNotification |
|
1387 // --------------------------------------------------------- |
|
1388 // |
|
1389 void RHttpDownloadMgr::CancelSessionEventNotification() |
|
1390 { |
|
1391 CLOG_WRITE( "RHttpDownload::CancelSessionEventNotification" ) |
|
1392 |
|
1393 SendReceive( EHttpDownloadMgrSessionEventCancel, TIpcArgs() ); |
|
1394 } |
|
1395 |
|
1396 // --------------------------------------------------------- |
|
1397 // RHttpDownloadMgr::PackedDefaultAttributesLC |
|
1398 // --------------------------------------------------------- |
|
1399 // |
|
1400 HBufC8* RHttpDownloadMgr::PackedDefaultAttributesLC() |
|
1401 { |
|
1402 HBufC8* buf = NULL; |
|
1403 if( iDefaultAttribs ) |
|
1404 { |
|
1405 |
|
1406 buf = TDMgrUtils::PackedAttributesL( iDefaultAttribs ); |
|
1407 CleanupStack::PushL( buf ); |
|
1408 } |
|
1409 else |
|
1410 { |
|
1411 buf = HBufC8::NewLC( 0 ); |
|
1412 } |
|
1413 |
|
1414 return buf; |
|
1415 } |
|
1416 |
|
1417 // --------------------------------------------------------- |
|
1418 // RHttpDownloadMgr::DoFindDownloadL |
|
1419 // --------------------------------------------------------- |
|
1420 // |
|
1421 RHttpDownload* RHttpDownloadMgr::DoFindDownloadL( const TDesC8& aUrl, const TDesC8& aMsgBody ) |
|
1422 { |
|
1423 RHttpDownload* retVal = NULL; |
|
1424 TInt pushCounter( 0 ); |
|
1425 |
|
1426 HBufC8* escaped = EscapeUtils::EscapeDecodeL( aUrl ); |
|
1427 CleanupStack::PushL( escaped ); ++pushCounter; |
|
1428 |
|
1429 TUriParser8 compUri; |
|
1430 compUri.Parse( *escaped ); |
|
1431 |
|
1432 TPtrC8 scheme( compUri.Extract( EUriScheme ) ); |
|
1433 |
|
1434 CUri8* url = CUri8::NewLC(); ++pushCounter; |
|
1435 |
|
1436 if( scheme.Length() ) |
|
1437 { |
|
1438 if( scheme != KHttpScheme && |
|
1439 scheme != KHttpsScheme ) |
|
1440 // this url has an unsupported scheme |
|
1441 { |
|
1442 User::Leave( KErrArgument ); |
|
1443 } |
|
1444 else |
|
1445 { |
|
1446 url->SetComponentL( scheme, EUriScheme ); |
|
1447 } |
|
1448 } |
|
1449 else |
|
1450 { |
|
1451 url->SetComponentL( KHttpScheme, EUriScheme ); |
|
1452 } |
|
1453 |
|
1454 url->SetComponentL( compUri.Extract( EUriHost ), EUriHost ); |
|
1455 url->SetComponentL( compUri.Extract( EUriPath ), EUriPath ); |
|
1456 url->SetComponentL( compUri.Extract( EUriQuery ), EUriQuery ); |
|
1457 url->SetComponentL( compUri.Extract( EUriFragment ), EUriFragment ); |
|
1458 |
|
1459 if( compUri.IsPresent( EUriPort ) ) |
|
1460 { |
|
1461 url->SetComponentL( compUri.Extract( EUriPort ), EUriPort ); |
|
1462 } |
|
1463 else |
|
1464 { |
|
1465 TBuf8<10> port; |
|
1466 |
|
1467 port.Format( _L8("%d"), KDefaultPort ); |
|
1468 |
|
1469 url->SetComponentL( port, EUriPort ); |
|
1470 } |
|
1471 |
|
1472 TBuf8<KHashLength> hash_req; |
|
1473 HashL( aMsgBody, hash_req ); |
|
1474 |
|
1475 TUriParser8 parsed_req; |
|
1476 |
|
1477 parsed_req.Parse( url->Uri().UriDes() ); |
|
1478 |
|
1479 for( TInt i = 0; i < iDownloadArray->Count(); i++ ) |
|
1480 { |
|
1481 if( (*iDownloadArray)[i]->IsDownloadL( parsed_req, hash_req ) ) |
|
1482 { |
|
1483 retVal = (*iDownloadArray)[i]; |
|
1484 break; |
|
1485 } |
|
1486 } |
|
1487 |
|
1488 CleanupStack::PopAndDestroy( pushCounter ); |
|
1489 |
|
1490 return retVal; |
|
1491 } |
|
1492 |
|
1493 // --------------------------------------------------------- |
|
1494 // RHttpDownloadMgr::IsEventBroadcasting |
|
1495 // --------------------------------------------------------- |
|
1496 // |
|
1497 TBool RHttpDownloadMgr::IsEventBroadcasting() |
|
1498 { |
|
1499 CLOG_WRITE( "RHttpDownload::IsEventBroadcasting" ) |
|
1500 return (0 < iExtension->iEventBroadcastLevel); |
|
1501 } |
|
1502 |
|
1503 // --------------------------------------------------------- |
|
1504 // RHttpDownloadMgr::IsEventBroadcasting |
|
1505 // --------------------------------------------------------- |
|
1506 // |
|
1507 TInt RHttpDownloadMgr::EventPriorityFlag() const |
|
1508 { |
|
1509 return iExtension->iAdjustEventPriorityFlag; |
|
1510 } |
|
1511 |
|
1512 // --------------------------------------------------------- |
|
1513 // RHttpDownloadMgr::IncrementEventPriorityFlag |
|
1514 // --------------------------------------------------------- |
|
1515 // |
|
1516 void RHttpDownloadMgr::IncrementEventPriorityFlag() |
|
1517 { |
|
1518 iExtension->iAdjustEventPriorityFlag++; |
|
1519 } |
|
1520 |
|
1521 // --------------------------------------------------------- |
|
1522 // RHttpDownloadMgr::IncrementEventPriorityFlag |
|
1523 // --------------------------------------------------------- |
|
1524 // |
|
1525 void RHttpDownloadMgr::DecrementEventPriorityFlag() |
|
1526 { |
|
1527 iExtension->iAdjustEventPriorityFlag--; |
|
1528 } |