|
1 /* |
|
2 * Copyright (c) 2006-2007 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: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #ifndef C_CATALOGSHTTPDOWNLOAD_H |
|
20 #define C_CATALOGSHTTPDOWNLOAD_H |
|
21 |
|
22 #include <DownloadMgrClient.h> |
|
23 |
|
24 #include <s32file.h> |
|
25 |
|
26 #include "catalogshttpoperation.h" |
|
27 #include "catalogstransportoperationid.h" |
|
28 #include "catalogshttpconfigobserver.h" |
|
29 #include "catalogshttpobserver.h" |
|
30 |
|
31 class MCatalogsHttpConfig; |
|
32 class CCatalogsHttpConfig; |
|
33 class CCatalogsHttpHeaders; |
|
34 class CCatalogsKeyValuePair; |
|
35 class CCatalogsHttpDownloadManager; |
|
36 |
|
37 /** |
|
38 * HTTP file download implementation |
|
39 * |
|
40 * @note Due to insufficient access to HTTP response headers through the |
|
41 * Download manager, Download uses CCatalogsHttpTransaction with HTTP HEAD |
|
42 * to get the response headers if the target filename cannot be figured out |
|
43 * from the given URL |
|
44 * @note Getting all of the response headers can be forced through SetHeaderMode() |
|
45 * |
|
46 */ |
|
47 class CCatalogsHttpDownload : public CBase, |
|
48 public MCatalogsHttpOperation, |
|
49 public MCatalogsHttpConfigObserver, |
|
50 public MCatalogsHttpObserver |
|
51 { |
|
52 public: |
|
53 |
|
54 enum TDownloadDeleteState |
|
55 { |
|
56 /** |
|
57 * RHttpDownload object can be deleted if necessary |
|
58 */ |
|
59 EDownloadCanBeDeleted = 0, |
|
60 |
|
61 /** |
|
62 * Download was paused by the client and RHttpDownload must |
|
63 * not be deleted |
|
64 */ |
|
65 EDownloadPaused |
|
66 }; |
|
67 |
|
68 public: // Constructors & destructor |
|
69 |
|
70 |
|
71 /** |
|
72 * Creator |
|
73 * |
|
74 * @param aDownload Platform download |
|
75 * @param aConfig Configuration |
|
76 * @return A new HTTP download |
|
77 */ |
|
78 static CCatalogsHttpDownload* NewLC( |
|
79 CCatalogsHttpDownloadManager& aOwner, |
|
80 RHttpDownload* aDownload, |
|
81 const CCatalogsHttpConfig& aConfig ); |
|
82 |
|
83 |
|
84 /** |
|
85 * Destructor |
|
86 */ |
|
87 ~CCatalogsHttpDownload(); |
|
88 |
|
89 |
|
90 public: // MCatalogsTransportOperation |
|
91 |
|
92 TInt AddRef(); |
|
93 |
|
94 TInt Release(); |
|
95 |
|
96 TInt RefCount() const; |
|
97 |
|
98 TInt Cancel(); |
|
99 |
|
100 TCatalogsTransportProgress Progress() const; |
|
101 |
|
102 |
|
103 public: // MCatalogsHttpOperation |
|
104 |
|
105 /** |
|
106 * @see MCatalogsHttpOperation::Start() |
|
107 */ |
|
108 TInt Start( TResumeStartInformation aResumeOrigin = EResumeFromUser ); |
|
109 |
|
110 |
|
111 /** |
|
112 * @see MCatalogsHttpOperation::Pause() |
|
113 */ |
|
114 TInt Pause(); |
|
115 |
|
116 |
|
117 /** |
|
118 * @see MCatalogsHttpOperation::NotifyCancel() |
|
119 */ |
|
120 virtual void NotifyCancel(); |
|
121 |
|
122 |
|
123 // Body and headers |
|
124 |
|
125 /** |
|
126 * @see MCatalogsHttpOperation::SetBodyL( const TDesC8& ) |
|
127 * @note Downloads do not support this |
|
128 */ |
|
129 void SetBodyL( const TDesC8& aBody ); |
|
130 |
|
131 |
|
132 /** |
|
133 * @see MCatalogsHttpOperation::SetBodyL( const TDesC16& ) |
|
134 */ |
|
135 void SetBodyL( const TDesC16& aBody ); |
|
136 |
|
137 |
|
138 /** |
|
139 * @see MCatalogsHttpOperation::Body() |
|
140 * @note For downloads, this always returns an empty descriptor. |
|
141 */ |
|
142 const TDesC8& Body() const; |
|
143 |
|
144 |
|
145 /** |
|
146 * @see MCatalogsHttpOperation::SetUriL() |
|
147 */ |
|
148 void SetUriL( const TDesC8& aUri ); |
|
149 |
|
150 |
|
151 /** |
|
152 * @see MCatalogsHttpOperation::SetUriL() |
|
153 */ |
|
154 void SetUriL( const TDesC16& aUri ); |
|
155 |
|
156 /** |
|
157 * @see MCatalogsHttpOperation::Uri() |
|
158 */ |
|
159 const TDesC8& Uri() const; |
|
160 |
|
161 |
|
162 /** |
|
163 * Returns the current configuration for the download |
|
164 * |
|
165 * The changes to the configuration must be made before |
|
166 * the download is started. Changes in priority can be made even |
|
167 * if the download is running but they have effect only if the download |
|
168 * is paused. |
|
169 * |
|
170 * @return Download configuration |
|
171 * @see MCatalogsHttpOperation::Config() |
|
172 */ |
|
173 MCatalogsHttpConfig& Config() const; |
|
174 |
|
175 |
|
176 /** |
|
177 * @see MCatalogsHttpOperation::RequestHeadersL() |
|
178 */ |
|
179 MCatalogsHttpHeaders& RequestHeadersL() const; |
|
180 |
|
181 /** |
|
182 * @see MCatalogsHttpOperation::ResponseHeadersL() |
|
183 */ |
|
184 const MCatalogsHttpHeaders& ResponseHeadersL() const; |
|
185 |
|
186 |
|
187 /** |
|
188 * @see MCatalogsHttpOperation::OperationType() |
|
189 */ |
|
190 TCatalogsHttpOperationType OperationType() const; |
|
191 |
|
192 |
|
193 /** |
|
194 * @see MCatalogsHttpOperation::OperationId() |
|
195 */ |
|
196 const TCatalogsTransportOperationId& OperationId() const; |
|
197 |
|
198 /** |
|
199 * @see MCatalogsHttpOperation::SetContentType( const TDesC8&) |
|
200 * @note Downloads do not support this |
|
201 */ |
|
202 void SetContentTypeL( const TDesC8& aContentType ); |
|
203 |
|
204 /** |
|
205 * @see MCatalogsHttpOperation::SetContentType( const TDesC16&) |
|
206 * @note Downloads do not support this |
|
207 */ |
|
208 void SetContentTypeL( const TDesC16& aContentType ); |
|
209 |
|
210 |
|
211 /** |
|
212 * @see MCatalogsHttpOperation::ContentType() |
|
213 */ |
|
214 const TDesC8& ContentType() const; |
|
215 |
|
216 |
|
217 /** |
|
218 * @see MCatalogsHttpOperation::ContentSize() |
|
219 */ |
|
220 TInt32 ContentSize() const; |
|
221 |
|
222 |
|
223 /** |
|
224 * @see MCatalogsHttpOperation::TransferredSize() |
|
225 */ |
|
226 TInt32 TransferredSize() const; |
|
227 |
|
228 |
|
229 /** |
|
230 * @see MCatalogsHttpOperation::IsPausable() |
|
231 */ |
|
232 TBool IsPausable() const; |
|
233 |
|
234 |
|
235 /** |
|
236 * Not supported |
|
237 * @see MCatalogsHttpOperation::StatusCode() |
|
238 */ |
|
239 TInt StatusCode() const; |
|
240 |
|
241 |
|
242 /** |
|
243 * Not supported |
|
244 * @see MCatalogsHttpOperation::StatusText() |
|
245 */ |
|
246 const TDesC8& StatusText() const; |
|
247 |
|
248 |
|
249 |
|
250 /** |
|
251 * @see MCatalogsHttpOperation::SetConnection() |
|
252 */ |
|
253 void SetConnection( CCatalogsConnection& aConnection ); |
|
254 |
|
255 |
|
256 /** |
|
257 * @see MCatalogsHttpOperation::ReportConnectionError() |
|
258 */ |
|
259 void ReportConnectionError( TInt aError ); |
|
260 |
|
261 |
|
262 /** |
|
263 * @see MCatalogsHttpOperation::ConnectionManager() |
|
264 */ |
|
265 CCatalogsHttpConnectionManager& ConnectionManager(); |
|
266 |
|
267 void ExternalizeL( RWriteStream& aStream ) const; |
|
268 void InternalizeL( RReadStream& aStream ); |
|
269 |
|
270 TCatalogsHttpOperationState State() const; |
|
271 |
|
272 |
|
273 public: // From MCatalogsHttpConfigObserver |
|
274 |
|
275 TInt HandleHttpConfigEvent( MCatalogsHttpConfig* aConfig, |
|
276 const TCatalogsHttpConfigEvent& aEvent ); |
|
277 |
|
278 public: // From MCatalogsHttpObserver |
|
279 |
|
280 void HandleHttpEventL( MCatalogsHttpOperation& aOperation, |
|
281 TCatalogsHttpEvent aEvent ); |
|
282 |
|
283 TBool HandleHttpError( MCatalogsHttpOperation& aOperation, |
|
284 TCatalogsHttpError aError ); |
|
285 |
|
286 public: |
|
287 |
|
288 /** |
|
289 * Handles events from Download Manager |
|
290 * |
|
291 * @param aEvent Download Manager event |
|
292 */ |
|
293 void HandleEventL( THttpDownloadEvent aEvent ); |
|
294 |
|
295 |
|
296 /** |
|
297 * Set file server session |
|
298 * |
|
299 * @param aFs File server session |
|
300 */ |
|
301 void SetFileServerSession( RFs& aFs ); |
|
302 |
|
303 |
|
304 #ifdef __SERIES60_31__ |
|
305 TBool IsCancelled() const; |
|
306 #endif |
|
307 |
|
308 public: |
|
309 |
|
310 /** |
|
311 * Sets the header mode |
|
312 * @param aMode Mode |
|
313 */ |
|
314 void SetHeaderMode( TCatalogsHttpHeaderMode aMode ); |
|
315 |
|
316 |
|
317 protected: |
|
318 |
|
319 /** |
|
320 * Constructor |
|
321 */ |
|
322 CCatalogsHttpDownload( |
|
323 CCatalogsHttpDownloadManager& aOwner, |
|
324 RHttpDownload* aDownload ); |
|
325 |
|
326 /** |
|
327 * 2nd phase constructor |
|
328 */ |
|
329 void ConstructL( const CCatalogsHttpConfig* aConfig ); |
|
330 |
|
331 protected: |
|
332 |
|
333 /** |
|
334 * Updates the content type for the download |
|
335 */ |
|
336 void UpdateContentType(); |
|
337 |
|
338 TInt GetDeleteState( TDownloadDeleteState& aStatus ); |
|
339 |
|
340 TInt SetDeleteState( const TDownloadDeleteState aStatus ); |
|
341 |
|
342 private: // New methods |
|
343 |
|
344 /** |
|
345 * Handles event progress |
|
346 * @param aEvent The event that has progressed |
|
347 */ |
|
348 void HandleEventProgressL( const THttpDownloadEvent& aEvent ); |
|
349 |
|
350 |
|
351 /** |
|
352 * Updates the target filename from Content-Disposition -header |
|
353 * @throw KErrNotFound if the header doesn't exist |
|
354 */ |
|
355 void UpdateFilenameFromContentDispositionL(); |
|
356 |
|
357 /** |
|
358 * Updates the target filename from DL manager |
|
359 */ |
|
360 void UpdateFilenameL(); |
|
361 |
|
362 |
|
363 /** |
|
364 * Updates the platform download to match the current configuration |
|
365 */ |
|
366 void UpdateDownloadConfigurationL(); |
|
367 |
|
368 |
|
369 /** |
|
370 * Updates the iUri to match the currently used uri |
|
371 */ |
|
372 void UpdateUriL(); |
|
373 |
|
374 |
|
375 /** |
|
376 * Updates the request headers to the platform DL manager |
|
377 */ |
|
378 void UpdateRequestHeadersL(); |
|
379 |
|
380 |
|
381 /** |
|
382 * Update the response headers from DL manager to the download |
|
383 */ |
|
384 void UpdateResponseHeadersL(); |
|
385 |
|
386 |
|
387 /** |
|
388 * Update the response headers from the transaction to the download |
|
389 */ |
|
390 void UpdateResponseHeadersL( MCatalogsHttpOperation& aOperation ); |
|
391 |
|
392 |
|
393 /** |
|
394 * Checks if the given header matches any of the request headers that have |
|
395 * an predefined enumeration in the platform DL manager |
|
396 * |
|
397 * @param aHeader Header |
|
398 * @return Header enumeration |
|
399 */ |
|
400 TUint MatchWithPredefinedRequestHeader( |
|
401 const TDesC8& aHeader ) const; |
|
402 |
|
403 |
|
404 /** |
|
405 * Checks if the given header matches any of the general headers that have |
|
406 * an predefined enumeration in the platform DL manager |
|
407 * |
|
408 * @param aHeader Header |
|
409 * @return Header enumeration |
|
410 */ |
|
411 TUint MatchWithPredefinedGeneralHeader( |
|
412 const TDesC8& aHeader ) const; |
|
413 |
|
414 |
|
415 /** |
|
416 * Checks if the given header matches any of the entity headers that have |
|
417 * an predefined enumeration in the platform DL manager |
|
418 * |
|
419 * @param aHeader Header |
|
420 * @return Header enumeration |
|
421 */ |
|
422 TUint MatchWithPredefinedEntityHeader( |
|
423 const TDesC8& aHeader ) const; |
|
424 |
|
425 |
|
426 /** |
|
427 * Adds the header from the pair to the target in the format used by |
|
428 * platform's DL manager |
|
429 * |
|
430 * @param aTarget Target descriptor. Allocated/resized if necessary |
|
431 * @param aPair Key-value -pair holding the header key and value |
|
432 */ |
|
433 void AddRequestHeaderL( HBufC8*& aTarget, |
|
434 const CCatalogsKeyValuePair& aPair ); |
|
435 |
|
436 /** |
|
437 * Updates transferring flag if the state changes. Also notifies |
|
438 * owner of the change |
|
439 */ |
|
440 void SetTransferring( TBool aTransferring ); |
|
441 |
|
442 TInt StartDownload(); |
|
443 |
|
444 /** |
|
445 * Starts a OMA DD download if necessary |
|
446 * |
|
447 * @return ETrue if a DD download was started |
|
448 */ |
|
449 TBool StartDescriptorDownloadL(); |
|
450 |
|
451 /** |
|
452 * Deletes downloaded files |
|
453 * |
|
454 * Errors are ignored |
|
455 */ |
|
456 void DeleteFiles(); |
|
457 |
|
458 /** |
|
459 * Moves/renames the temp file as the target file |
|
460 */ |
|
461 void MoveFileL(); |
|
462 |
|
463 /** |
|
464 * Tries to parse the filename from the URI |
|
465 * |
|
466 * @note Filename from this kind of an URI "http://www.doh.com/dl=bigfile" |
|
467 * is "dl" so beware |
|
468 */ |
|
469 void ParseFilenameFromUriL(); |
|
470 |
|
471 /** |
|
472 * Returns ETrue if aDes != NULL and aDes->Length() > 0 |
|
473 */ |
|
474 TBool ContainsData( const HBufC* aDes ) const; |
|
475 |
|
476 /** |
|
477 * Gets the correct extension for iTempFilename by using dochandler |
|
478 * and ContentType() and sets it to iConfig |
|
479 */ |
|
480 void UpdateExtensionL(); |
|
481 |
|
482 /** |
|
483 * Checks the preset content-type and forces HEAD request if |
|
484 * content is OMA DD, JAD or some DRM file |
|
485 */ |
|
486 void UpdateHeadRequirement(); |
|
487 |
|
488 void InitializeDownloadL(); |
|
489 |
|
490 void DeletePlatformDownload(); |
|
491 |
|
492 /** |
|
493 * Updates the secondary id from platform download |
|
494 * Doesn't check if the download exists |
|
495 */ |
|
496 void UpdateSecondaryIdL(); |
|
497 |
|
498 void EncodeUriL(); |
|
499 |
|
500 const TDesC8& EncodedUri() const; |
|
501 |
|
502 |
|
503 private: |
|
504 |
|
505 CCatalogsHttpDownloadManager& iOwner; |
|
506 TCatalogsTransportOperationId iId; // Operation id |
|
507 RHttpDownload* iDownload; // Platform download |
|
508 CCatalogsHttpConfig* iConfig; // Configuration |
|
509 MCatalogsHttpObserver* iObserver; // Observer |
|
510 TCatalogsHttpEvent iState; // State of the download |
|
511 HBufC8* iUri; // Current URI |
|
512 HBufC8* iEncodedUri; // Current URI as encoded |
|
513 CCatalogsHttpHeaders* iResponseHeaders; // Headers from HTTP response |
|
514 |
|
515 // added request headers not supported by DL man |
|
516 HBufC8* iAddedRequestHeaders; |
|
517 TInt iRefCount; |
|
518 TBool iNormalDelete; |
|
519 TBuf8<KMaxContentTypeLength> iContentType; |
|
520 |
|
521 // Transaction for retrieving all of the response headers |
|
522 MCatalogsHttpOperation* iTransaction; |
|
523 TCatalogsHttpHeaderMode iMode; |
|
524 |
|
525 TBool iDdDownload; // True if downloading a DD |
|
526 RFile iDdFile; // Target file for DD |
|
527 RFs iFs; |
|
528 TInt iReconnectCount; // number of reconnect attempts |
|
529 |
|
530 TBool iPaused; |
|
531 |
|
532 TBool iReconnectWhenFail; |
|
533 |
|
534 TBool iTransferring; |
|
535 |
|
536 CCatalogsConnection* iConnection; // not owned |
|
537 TBool iFileIsSet; |
|
538 HBufC* iTempFilename; |
|
539 |
|
540 // mutable because this is only used as an optimization and is |
|
541 // updated in ContentSize() const |
|
542 mutable TInt32 iContentSize; |
|
543 |
|
544 TInt32 iTransferredSize; |
|
545 |
|
546 #ifdef __SERIES60_31__ |
|
547 TBool iCancelled; |
|
548 #endif |
|
549 |
|
550 // For managing async pause with dlmgr. |
|
551 TBool iPausePending; |
|
552 TBool iQueuedResume; |
|
553 |
|
554 protected: |
|
555 |
|
556 // Grant access to UpdateContentType |
|
557 friend class CCatalogsHttpDownloadManager; |
|
558 |
|
559 }; |
|
560 |
|
561 #endif // C_CATALOGSHTTPDOWNLOAD_H |