|
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: ?Description |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include <httpstringconstants.h> |
|
20 #include <rhttpheaders.h> |
|
21 #include <mmfcontrollerpluginresolver.h> //to get the supported MIME types |
|
22 #ifdef _DEBUG |
|
23 #include <bautils.h> |
|
24 #include "irreportsettings.h" |
|
25 #endif |
|
26 #include "irdataprovider.h" |
|
27 #include "irdebug.h" |
|
28 #include "irhttpdataprovider.h" |
|
29 #include "irhttppost.h" |
|
30 #include "irhttprequestdata.h" |
|
31 #include "irnetworkcontroller.h" |
|
32 #include "irdatatransferobserver.h" |
|
33 #include "irlogodownloadengine.h" |
|
34 #include "irfavoritesdb.h" |
|
35 #include "irsettings.h" |
|
36 |
|
37 //Added for ALR/SNAP |
|
38 const TInt KBufflengthMaxLength = 255; |
|
39 const TInt KWapProfileMaxLength = 20; |
|
40 const TInt KNokiaIrAppAcceptMaxLength = 25; |
|
41 const TInt KSize = 1024; |
|
42 const TInt KMaxSize = 2048; |
|
43 const TInt KBufSize = 10; |
|
44 const TUid KUidHelixController = { 0x101F8514 }; // Helix Video controller UID |
|
45 |
|
46 // --------------------------------------------------------------------------- |
|
47 // CIRHttpDataProvider::CIRHttpDataProvider(MIRHttpDataProviderObserver& |
|
48 // aObserver):iObserver(aObserver),iRunning(EFalse) |
|
49 // Creates instance of CIRHttpDataProvider. |
|
50 // --------------------------------------------------------------------------- |
|
51 // |
|
52 CIRHttpDataProvider::CIRHttpDataProvider( MIRHttpDataProviderObserver |
|
53 &aObserver ): iRunning( EFalse ), iObserver( aObserver ) |
|
54 { |
|
55 IRLOG_DEBUG( "CIRHttpDataProvider::CIRHttpDataProvider" ); |
|
56 // Definition not required |
|
57 } |
|
58 |
|
59 // --------------------------------------------------------------------------- |
|
60 // CIRHttpDataProvider::~CIRHttpDataProvider() |
|
61 // Destructs instance of CIRHttpDataProvider. |
|
62 // --------------------------------------------------------------------------- |
|
63 // |
|
64 CIRHttpDataProvider::~CIRHttpDataProvider() |
|
65 { |
|
66 IRLOG_DEBUG( "CIRHttpDataProvider::~CIRHttpDataProvider - Entering" ); |
|
67 iHttpSession.Close(); |
|
68 delete iLogMessage; |
|
69 if(iIRNetworkControllerHandle) |
|
70 { |
|
71 iIRNetworkControllerHandle->Close(); |
|
72 } |
|
73 if(iLogoDownloadEngine) |
|
74 { |
|
75 delete iLogoDownloadEngine; |
|
76 iLogoDownloadEngine = NULL; |
|
77 } |
|
78 IRLOG_DEBUG( "CIRHttpDataProvider::~CIRHttpDataProvider - Exiting." ); |
|
79 } |
|
80 |
|
81 |
|
82 // --------------------------------------------------------------------------- |
|
83 // CIRHttpDataProvider::NewL(MIRHttpDataProviderObserver& aObserver ) |
|
84 // Creates instance of CIRHttpDataProvider. |
|
85 // --------------------------------------------------------------------------- |
|
86 // |
|
87 CIRHttpDataProvider *CIRHttpDataProvider::NewL( MIRHttpDataProviderObserver |
|
88 &aObserver ) |
|
89 { |
|
90 IRLOG_DEBUG( "CIRHttpDataProvider::NewL - Entering" ); |
|
91 CIRHttpDataProvider *self = NewLC( aObserver ); |
|
92 CleanupStack::Pop(self); |
|
93 IRLOG_DEBUG( "CIRHttpDataProvider::NewL - Exiting" ); |
|
94 return self; |
|
95 } |
|
96 |
|
97 // --------------------------------------------------------------------------- |
|
98 // CIRHttpDataProvider::NewLC(MIRHttpDataProviderObserver& aObserver) |
|
99 // Creates instance of CIRHttpDataProvider. |
|
100 // --------------------------------------------------------------------------- |
|
101 // |
|
102 CIRHttpDataProvider *CIRHttpDataProvider::NewLC( MIRHttpDataProviderObserver |
|
103 &aObserver ) |
|
104 { |
|
105 IRLOG_DEBUG( "CIRHttpDataProvider::NewLC - Entering" ); |
|
106 CIRHttpDataProvider *self = new( ELeave )CIRHttpDataProvider( aObserver ); |
|
107 CleanupStack::PushL( self ); |
|
108 self->ConstructL(); |
|
109 IRLOG_DEBUG( "CIRHttpDataProvider::NewLC - Exiting" ); |
|
110 return self; |
|
111 } |
|
112 |
|
113 // --------------------------------------------------------------------------- |
|
114 // CIRHttpDataProvider::ConstructL() |
|
115 // 2nd phase construction |
|
116 // --------------------------------------------------------------------------- |
|
117 // |
|
118 void CIRHttpDataProvider::ConstructL() |
|
119 { |
|
120 IRLOG_DEBUG( "CIRHttpDataProvider::ConstructL - Entering" ); |
|
121 iFirstTime = ETrue; |
|
122 iIRNetworkControllerHandle = CIRNetworkController::OpenL(); |
|
123 iLogMessage = CIRHttpPost::NewL(iHttpTransaction); |
|
124 iLogoDownloadEngine = CIRLogoDownloadEngine::NewL(); |
|
125 IRLOG_DEBUG( "CIRHttpDataProvider::ConstructL - Exiting" ); |
|
126 } |
|
127 |
|
128 EXPORT_C CIRLogoDownloadEngine* CIRHttpDataProvider::GetLogoDownloadEngine() |
|
129 { |
|
130 IRLOG_DEBUG( "CIRHttpDataProvider::GetLogoDownloadEngine" ); |
|
131 return iLogoDownloadEngine; |
|
132 } |
|
133 |
|
134 // --------------------------------------------------------------------------- |
|
135 // CIRHttpDataProvider::CancelTransactionL() |
|
136 // Cancel the issued Http transaction |
|
137 // --------------------------------------------------------------------------- |
|
138 // |
|
139 void CIRHttpDataProvider::CancelTransaction() |
|
140 { |
|
141 IRLOG_DEBUG( "CIRHttpDataProvider::CancelTransaction - Entering" ); |
|
142 // Make sure that logfile is closed |
|
143 CloseLogFile (); |
|
144 if ( !iRunning ) |
|
145 { |
|
146 return ; |
|
147 } |
|
148 // Close() also cancels transaction (Cancel() can also be used but |
|
149 // resources allocated by transaction must be still freed with Close()) |
|
150 iHttpTransaction.Close(); |
|
151 // Not running anymore |
|
152 iRunning = EFalse; |
|
153 IRLOG_DEBUG( "CIRHttpDataProvider::CancelTransaction - Exiting." ); |
|
154 } |
|
155 |
|
156 // --------------------------------------------------------------------------- |
|
157 // CIRHttpDataProvider::CloseLogFile ( CIRHttpRequestData& aRequestInfo ) |
|
158 // Used to Close the log file LogUsage.gz externally from other sources (bug-fixing) |
|
159 // --------------------------------------------------------------------------- |
|
160 // |
|
161 void CIRHttpDataProvider::CloseLogFile () |
|
162 { |
|
163 IRLOG_DEBUG( "CIRHttpDataProvider::CloseLogFile - Entering" ); |
|
164 if (iLogMessage) iLogMessage->CloseLogFile (); |
|
165 IRLOG_DEBUG( "CIRHttpDataProvider::CloseLogFile - Exiting" ); |
|
166 } |
|
167 |
|
168 // --------------------------------------------------------------------------- |
|
169 // CIRHttpDataProvider::IssueHttpRequestL( CIRHttpRequestData& aRequestInfo ) |
|
170 // Used to issue the request. |
|
171 // --------------------------------------------------------------------------- |
|
172 // |
|
173 TInt CIRHttpDataProvider::IssueHttpRequestL( CIRHttpRequestData &aRequestInfo ) |
|
174 { |
|
175 IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - Entering" ); |
|
176 IRRDEBUG2("CIRHTTPDATAPROVIDER::IRHTTPISSUEREQUESTL",KNullDesC); |
|
177 iNotModified = EFalse; |
|
178 |
|
179 if ( !( iIRNetworkControllerHandle->GetNetworkStatus() ) ) |
|
180 { |
|
181 // Error Network connection inactive |
|
182 return KErrCouldNotConnect; |
|
183 } |
|
184 if ( iFirstTime ) |
|
185 { |
|
186 InitializeHttpDataProviderL(); |
|
187 iIRNetworkControllerHandle->InitializeHttpSessionL( iHttpSession, |
|
188 MIRDataTransferTracker::EIRTransferCategoryIsds); |
|
189 iFirstTime = EFalse; |
|
190 } |
|
191 // Parse string to URI (as defined in RFC2396) |
|
192 TUriParser8 uri; |
|
193 uri.Parse( aRequestInfo.iUri ); |
|
194 // Get request method string |
|
195 RStringF method; |
|
196 switch ( aRequestInfo.iMethod ) |
|
197 { |
|
198 case EIRHttpGET: |
|
199 { |
|
200 method = iHttpSession.StringPool().StringF( HTTP::EGET, |
|
201 RHTTPSession::GetTable() ); |
|
202 } |
|
203 break; |
|
204 case EIRHttpPOST: |
|
205 { |
|
206 method = iHttpSession.StringPool().StringF( HTTP::EPOST, |
|
207 RHTTPSession::GetTable() ); |
|
208 } |
|
209 break; |
|
210 default: |
|
211 { |
|
212 } |
|
213 break; |
|
214 } |
|
215 CleanupClosePushL( method ); |
|
216 |
|
217 IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - Opening transaction" ); |
|
218 // Open transaction with previous method and parsed uri. This class will |
|
219 // receive transaction events in MHFRunL and MHFRunError. |
|
220 iHttpTransaction = iHttpSession.OpenTransactionL( uri, *this, method ); |
|
221 |
|
222 #ifdef _DEBUG |
|
223 RFs iFs; |
|
224 User::LeaveIfError(iFs.Connect()); |
|
225 |
|
226 TTime timeStamp; |
|
227 //timeStamp.UniversalTime(); |
|
228 timeStamp.HomeTime(); |
|
229 TDateTime dateTime = timeStamp.DateTime(); |
|
230 |
|
231 _LIT(KFormatTime,"-%d-%d-%d %d.%d.%d.xml.gz\n"); |
|
232 TBuf<32> sendTime; |
|
233 sendTime.Format(KFormatTime,dateTime.Year(),TInt(dateTime.Month()+1),dateTime.Day()+1, |
|
234 dateTime.Hour(),dateTime.Minute(),dateTime.Second()); |
|
235 |
|
236 _LIT( KDstFilePath, "c:\\data\\IR_Log\\"); |
|
237 TFileName dstFileName(KDstFilePath); |
|
238 dstFileName.Append(KGZipLogFileName); |
|
239 dstFileName.Append(sendTime); |
|
240 |
|
241 iFs.MkDirAll(dstFileName); |
|
242 |
|
243 if ( aRequestInfo.iMethod == EIRHttpPOST ) |
|
244 { |
|
245 CIRSettings * settings = CIRSettings::OpenL(); |
|
246 if(NULL != settings) |
|
247 { |
|
248 TFileName filePath = settings->PrivatePath(); |
|
249 filePath.Append( KGZipLogFileName ); |
|
250 |
|
251 BaflUtils::CopyFile(iFs, filePath, dstFileName); |
|
252 settings->Close(); |
|
253 } |
|
254 } |
|
255 #endif |
|
256 |
|
257 if ( aRequestInfo.iMethod == EIRHttpPOST ) |
|
258 { |
|
259 IRLOG_DEBUG( "CIRHttpDataProvider::IssueHttpRequestL - POST method" ); |
|
260 // Close the LogFile |
|
261 iLogMessage->CloseLogFile (); |
|
262 iLogMessage->SetTransaction( iHttpTransaction ); |
|
263 TInt FileSize(KErrNone); |
|
264 TRAPD(err, iLogMessage->GetFileToPostL(&FileSize)); |
|
265 if( err ) |
|
266 { |
|
267 // failed to open the file to be posted hence cancel the request |
|
268 CleanupStack::PopAndDestroy(&method); |
|
269 iHttpTransaction.Close(); |
|
270 return KErrCouldNotConnect; |
|
271 } |
|
272 TBuf8<KBufflengthMaxLength> bufflength; |
|
273 _LIT8(KFormat,"%d"); |
|
274 bufflength.Format(KFormat,FileSize); |
|
275 aRequestInfo.iContentType.Copy(KPostContentType); |
|
276 RHTTPRequest LogRequest; |
|
277 LogRequest = iHttpTransaction.Request(); |
|
278 LogRequest.SetBody((MHTTPDataSupplier&) *iLogMessage); |
|
279 RHTTPHeaders header = iHttpTransaction.Request().GetHeaderCollection(); |
|
280 SetHeaderL(header,HTTP::EContentType,aRequestInfo.iContentType ); |
|
281 SetHeaderL(header,HTTP::EContentLength,bufflength); |
|
282 } |
|
283 |
|
284 |
|
285 // Setup the headers for the HTTP request |
|
286 BuildHeadersL(aRequestInfo); |
|
287 |
|
288 // Submit the transaction. After this the framework will give transaction |
|
289 // events via MHFRunL and MHFRunError. |
|
290 iHttpTransaction.SubmitL(); |
|
291 |
|
292 #ifdef _DEBUG |
|
293 if ( aRequestInfo.iMethod == EIRHttpPOST ) |
|
294 { |
|
295 _LIT( KSentPrefix, "X__"); |
|
296 TFileName sentLogFileName(KDstFilePath); |
|
297 sentLogFileName.Append(KSentPrefix); |
|
298 sentLogFileName.Append(KGZipLogFileName); |
|
299 sentLogFileName.Append(sendTime); |
|
300 BaflUtils::RenameFile(iFs, dstFileName, sentLogFileName); |
|
301 } |
|
302 iFs.Close(); |
|
303 #endif |
|
304 |
|
305 CleanupStack::PopAndDestroy( &method ); |
|
306 iRunning = ETrue; |
|
307 IRLOG_INFO( "CIRHttpDataProvider::IssueHttpRequestL - Submitted HTTP request" ); |
|
308 return KErrNone; |
|
309 } |
|
310 |
|
311 // --------------------------------------------------------------------------- |
|
312 // CIRHttpDataProvider::SetHttpContentType(TDesC& aContentType,TDesC& aCharSet) |
|
313 // Set the Http content type |
|
314 // --------------------------------------------------------------------------- |
|
315 // |
|
316 void CIRHttpDataProvider::SetHttpContentType( const TDesC &aContentType, |
|
317 const TDesC &aCharSet ) |
|
318 { |
|
319 IRLOG_DEBUG( "CIRHttpDataProvider::SetHttpContentType - Entering" ); |
|
320 iContentType.Copy( aContentType ); |
|
321 iCharSet.Copy( aCharSet ); |
|
322 IRLOG_DEBUG( "CIRHttpDataProvider::SetHttpContentType - Exiting." ); |
|
323 } |
|
324 |
|
325 |
|
326 void CIRHttpDataProvider::InitializeHttpDataProviderL() |
|
327 { |
|
328 IRLOG_DEBUG( "CIRHttpDataProvider::InitializeHttpDataProviderL - Entering" ); |
|
329 iHttpSession.Close(); |
|
330 TRAPD( LeaveValue, iHttpSession.OpenL() ); |
|
331 if ( LeaveValue != KErrNone ) |
|
332 { |
|
333 // Most common error; no access point configured, and session creation |
|
334 // leaves with KErrNotFound. |
|
335 // Load a string from the resource file and add the error code to string |
|
336 User::Leave( LeaveValue ); |
|
337 } |
|
338 // Set the HTTP connection properties |
|
339 RStringPool strP = iHttpSession.StringPool(); |
|
340 RHTTPConnectionInfo connInfo = iHttpSession.ConnectionInfo(); |
|
341 // RSocketServ Handle |
|
342 connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketServ, |
|
343 RHTTPSession::GetTable() ), |
|
344 THTTPHdrVal( iIRNetworkControllerHandle->GetIRSocketServer().Handle() ) ); |
|
345 // RConnection Handle |
|
346 TInt connPtr = REINTERPRET_CAST( TInt, |
|
347 &( iIRNetworkControllerHandle->GetIRConnection() ) ); |
|
348 |
|
349 connInfo.SetPropertyL( strP.StringF( HTTP::EHttpSocketConnection, |
|
350 RHTTPSession::GetTable() ), THTTPHdrVal( connPtr ) ); |
|
351 // HTTP Version ( Specify that i am using HTTP/1.1 |
|
352 |
|
353 connInfo.SetPropertyL( strP.StringF( HTTP::EVersion, |
|
354 RHTTPSession::GetTable() ), |
|
355 THTTPHdrVal( strP.StringF( HTTP::EHttp11, RHTTPSession::GetTable() ) ) ); |
|
356 |
|
357 RStringF temp = strP.OpenFStringL( KAccept ); |
|
358 CleanupClosePushL( temp ); |
|
359 connInfo.SetPropertyL( strP.StringF( HTTP::EAccept, |
|
360 RHTTPSession::GetTable() ), THTTPHdrVal( temp ) ); |
|
361 |
|
362 CleanupStack::PopAndDestroy( &temp ); |
|
363 iContentType.Copy( KDefaultContentType ); |
|
364 iCharSet.Copy( KDefaultCharSet ); |
|
365 |
|
366 IRLOG_DEBUG( "CIRHttpDataProvider::InitializeHttpDataProviderL - Exiting." ); |
|
367 } |
|
368 |
|
369 |
|
370 // --------------------------------------------------------------------------- |
|
371 // CIRHttpDataProvider::MHFRunL() |
|
372 // Inherited from MHTTPTransactionCallback |
|
373 // Called by framework to pass transaction events. |
|
374 // --------------------------------------------------------------------------- |
|
375 // |
|
376 |
|
377 void CIRHttpDataProvider::MHFRunL( RHTTPTransaction aTransaction, |
|
378 const THTTPEvent &aEvent ) |
|
379 { |
|
380 IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunL - Entering." ); |
|
381 |
|
382 switch ( aEvent.iStatus ) |
|
383 { |
|
384 case THTTPEvent::EGotResponseHeaders: |
|
385 { |
|
386 IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - THTTPEvent::EGotResponseHeaders" ); |
|
387 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNL--HEADERS",KNullDesC); |
|
388 // HTTP response headers have been received. Use |
|
389 // aTransaction.Response() to get the response. However, it's not |
|
390 // necessary to do anything with the response when this event occurs. |
|
391 // Get HTTP status code from header (e.g. 200) |
|
392 RHTTPResponse resp = aTransaction.Response(); |
|
393 iStatusCode = resp.StatusCode(); |
|
394 // Get status text (e.g. "OK") |
|
395 iStatusText.Copy( |
|
396 ( const unsigned short int* )resp.StatusText().DesC().Ptr(), |
|
397 iStatusText.MaxLength() ); |
|
398 // Extract header field names and value |
|
399 ExtractResponseHeadersL( aTransaction ); |
|
400 // Validate the status code |
|
401 ValidateStatusCode( iStatusCode ); |
|
402 } |
|
403 break; |
|
404 case THTTPEvent::EGotResponseBodyData: |
|
405 { |
|
406 // Part of response's body data received. Use |
|
407 // aTransaction.Response().Body()->GetNextDataPart() to get the actual |
|
408 // body data. |
|
409 // Get the body data supplier |
|
410 IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - THTTPEvent::EGotResponseBodyData" ); |
|
411 MHTTPDataSupplier *body = aTransaction.Response().Body(); |
|
412 TPtrC8 dataChunk; |
|
413 body->GetNextDataPart( dataChunk ); |
|
414 iObserver.HttpBodyReceived( dataChunk ); |
|
415 // To release the body data. |
|
416 body->ReleaseData(); |
|
417 } |
|
418 break; |
|
419 case THTTPEvent::ESucceeded: |
|
420 { |
|
421 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNL--SUCCEEDED",KNullDesC); |
|
422 // Transaction can be closed now. It's not needed anymore. |
|
423 aTransaction.Close(); |
|
424 iRunning = EFalse; |
|
425 iObserver.HttpEventComplete(); |
|
426 IRLOG_INFO( "CIRHttpDataProvider::MHFRunL - THTTPEvent::ESucceeded" ); |
|
427 } |
|
428 break; |
|
429 case THTTPEvent::EFailed: |
|
430 { |
|
431 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNL--FAILED",KNullDesC); |
|
432 // Transaction completed with failure. |
|
433 aTransaction.Close(); |
|
434 iRunning = EFalse; |
|
435 iObserver.HttpTransactionError( iStatusCode ); |
|
436 IRLOG_ERROR2( "CIRHttpDataProvider::MHFRunL - THTTPEvent::EFailed (status=%d)", iStatusCode ); |
|
437 } |
|
438 break; |
|
439 case THTTPEvent::ENotifyNewRequestBodyPart: |
|
440 { |
|
441 iLogMessage->ReleaseData(); |
|
442 } |
|
443 break; |
|
444 case KServiceUnavailable: |
|
445 { |
|
446 IRRDEBUG2("MHFRunl:KServiceUnavailable",KNullDesC); |
|
447 aTransaction.Close(); |
|
448 iRunning = EFalse; |
|
449 iObserver.HttpTransactionError(KServiceUnavailable); |
|
450 } |
|
451 break; |
|
452 case KDndTimedOut: |
|
453 { |
|
454 IRRDEBUG2("MHFRunL :KDndTimedOut ",KNullDesC); |
|
455 // Just close the transaction on errors |
|
456 aTransaction.Close(); |
|
457 iRunning = EFalse; |
|
458 iObserver.HttpTransactionError(KDndTimedOut); |
|
459 } |
|
460 break; |
|
461 default: |
|
462 // There are more events in THTTPEvent, |
|
463 // Which is needed can be implemented incase required |
|
464 // by the HTTP Data Provider |
|
465 { |
|
466 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNL--DEFAULT",KNullDesC); |
|
467 if ( aEvent.iStatus < 0 ) |
|
468 { |
|
469 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNL %d",aEvent.iStatus); |
|
470 // Just close the transaction on errors |
|
471 aTransaction.Close(); |
|
472 iRunning = EFalse; |
|
473 iObserver.HttpTransactionError( iStatusCode ); |
|
474 } |
|
475 // Other events are not errors |
|
476 // (e.g. permanent and temporary redirections) |
|
477 // ignore such errors |
|
478 } |
|
479 break; |
|
480 } |
|
481 IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunL - Exiting." ); |
|
482 } |
|
483 |
|
484 |
|
485 // --------------------------------------------------------------------------- |
|
486 // CIRHttpDataProvider::MHFRunError() |
|
487 // Inherited from MHTTPTransactionCallback |
|
488 // Called by framework to pass transaction errors |
|
489 // --------------------------------------------------------------------------- |
|
490 // |
|
491 TInt CIRHttpDataProvider::MHFRunError( TInt /* aError*/, |
|
492 RHTTPTransaction /*aTransaction*/, const THTTPEvent & /*aEvent*/ ) |
|
493 { |
|
494 IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunError - Entering" ); |
|
495 IRRDEBUG2("CIRHTTPDATAPROVIDER::MHFRUNERROR",KNullDesC); |
|
496 // Handle error and return KErrNone. |
|
497 IRLOG_DEBUG( "CIRHttpDataProvider::MHFRunError - Exiting." ); |
|
498 return KErrNone; |
|
499 } |
|
500 |
|
501 |
|
502 // --------------------------------------------------------------------------- |
|
503 // CIRHttpDataProvider::ExtractResponseHeadersL( RHTTPTransaction aTransaction ) |
|
504 // Used to Extract the response headers. |
|
505 // --------------------------------------------------------------------------- |
|
506 // |
|
507 |
|
508 void CIRHttpDataProvider::ExtractResponseHeadersL(const RHTTPTransaction& |
|
509 aTransaction ) |
|
510 { |
|
511 IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Entering" ); |
|
512 RHTTPResponse response = aTransaction.Response(); |
|
513 RHTTPHeaders respHeader = response.GetHeaderCollection(); |
|
514 THTTPHdrFieldIter iterator = respHeader.Fields(); |
|
515 RStringPool httpStringPool = aTransaction.Session().StringPool(); |
|
516 iterator.First(); |
|
517 HBufC8 *headerField = HBufC8::NewLC( KMaxHeaderNameLength + |
|
518 KMaxHeaderValueLength ); |
|
519 HBufC8 *fieldValBuf = HBufC8::NewLC( KMaxHeaderValueLength ); |
|
520 while ( iterator.AtEnd() == EFalse ) |
|
521 { |
|
522 RStringTokenF fieldName = iterator(); |
|
523 RStringF fieldNameStr = httpStringPool.StringF( fieldName ); |
|
524 THTTPHdrVal fieldVal; |
|
525 if ( respHeader.GetField( fieldNameStr, 0, fieldVal ) == KErrNone ) |
|
526 { |
|
527 const TDesC8 &fieldNameDesC = fieldNameStr.DesC(); |
|
528 headerField->Des().Copy( fieldNameDesC.Left( |
|
529 KMaxHeaderNameLength ) ); |
|
530 fieldValBuf->Des().Zero(); |
|
531 switch ( fieldVal.Type() ) |
|
532 { |
|
533 // the value is an integer |
|
534 //lint restore -e747:Significant prototype |
|
535 //coercion (arg. no. 1) int to long long : |
|
536 case THTTPHdrVal::KTIntVal: fieldValBuf->Des().Num( |
|
537 fieldVal.Int() ); |
|
538 break; |
|
539 // the value is a case-insensitive string |
|
540 case THTTPHdrVal::KStrFVal: |
|
541 { |
|
542 RStringF fieldValStr = httpStringPool.StringF( |
|
543 fieldVal.StrF() ); |
|
544 const TDesC8 &fieldValDesC = fieldValStr.DesC(); |
|
545 fieldValBuf->Des().Copy( fieldValDesC.Left( |
|
546 KMaxHeaderValueLength ) ); |
|
547 } |
|
548 break; |
|
549 // the value is a case-sensitive string |
|
550 case THTTPHdrVal::KStrVal: |
|
551 { |
|
552 RString fieldValStr = httpStringPool.String( |
|
553 fieldVal.Str() ); |
|
554 const TDesC8 &fieldValDesC = fieldValStr.DesC(); |
|
555 fieldValBuf->Des().Copy( fieldValDesC.Left( |
|
556 KMaxHeaderValueLength ) ); |
|
557 } |
|
558 break; |
|
559 // the value is a date/time |
|
560 case THTTPHdrVal::KDateVal: |
|
561 { |
|
562 TDateTime date = fieldVal.DateTime(); |
|
563 TTime t( date ); |
|
564 if ( !iSetNonUAProfUserAgent ) |
|
565 { |
|
566 iObserver.HttpDateHeaderReceived( *headerField ,t ); |
|
567 } |
|
568 } |
|
569 break; |
|
570 // the value is type is unknown |
|
571 default: |
|
572 break; |
|
573 } |
|
574 // Display HTTP header field name and value |
|
575 headerField->Des().Append( KDPColon ); |
|
576 headerField->Des().Append( *fieldValBuf ); |
|
577 iObserver.HttpHeaderReceived( *headerField ); |
|
578 } |
|
579 ++iterator; |
|
580 } |
|
581 |
|
582 CleanupStack::PopAndDestroy( fieldValBuf ); |
|
583 CleanupStack::PopAndDestroy( headerField ); |
|
584 IRLOG_DEBUG( "CIRHttpDataProvider::ExtractResponseHeadersL - Exiting." ); |
|
585 } |
|
586 |
|
587 |
|
588 // --------------------------------------------------------------------------- |
|
589 // CIRHttpDataProvider::SetHeaderL( RHTTPHeaders aHeaders, TInt aHeaderField, |
|
590 // const TDesC8& aHeaderValue ) |
|
591 // Used to set the Http header |
|
592 // --------------------------------------------------------------------------- |
|
593 // |
|
594 void CIRHttpDataProvider::SetHeaderL( RHTTPHeaders aHeaders, |
|
595 TInt aHeaderField, const TDesC8 &aHeaderValue ) const |
|
596 { |
|
597 IRLOG_DEBUG( "CIRHttpDataProvider::SetHeaderL - Entering" ); |
|
598 RStringF valStr = iHttpSession.StringPool().OpenFStringL( aHeaderValue ); |
|
599 CleanupClosePushL( valStr ); |
|
600 THTTPHdrVal val( valStr ); |
|
601 aHeaders.SetFieldL( iHttpSession.StringPool().StringF( aHeaderField, |
|
602 RHTTPSession::GetTable() ), val ); |
|
603 CleanupStack::PopAndDestroy( &valStr ); |
|
604 IRLOG_DEBUG( "CIRHttpDataProvider::SetHeaderL - Exiting." ); |
|
605 } |
|
606 |
|
607 // --------------------------------------------------------------------------- |
|
608 // CIRHttpDataProvider::BuildHeadersL(CIRHttpRequestData &aRequestInfo) |
|
609 // Build the headers for the request |
|
610 // --------------------------------------------------------------------------- |
|
611 // |
|
612 |
|
613 void CIRHttpDataProvider::BuildHeadersL(const CIRHttpRequestData &aRequestInfo) |
|
614 { |
|
615 IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - Entering" ); |
|
616 RBuf logstr; |
|
617 logstr.Create(KMaxSize); |
|
618 logstr.CleanupClosePushL(); |
|
619 // Set headers for request; user agent and accepted content type |
|
620 RHTTPHeaders header = iHttpTransaction.Request().GetHeaderCollection(); |
|
621 |
|
622 SetHeaderL( header, HTTP::EAccept, KAccept ); |
|
623 logstr.Copy(KAccept); |
|
624 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAccept = %S", &logstr ); |
|
625 |
|
626 // Set the User-Agent header to UAProf string |
|
627 SetHeaderL( header, HTTP::EUserAgent, |
|
628 iIRNetworkControllerHandle->GetUAProfString()->Des() ); |
|
629 logstr.Copy(iIRNetworkControllerHandle->GetUAProfString()->Des()); |
|
630 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EUserAgent = %S", &logstr ); |
|
631 |
|
632 // Set the Accept Character set header |
|
633 SetHeaderL( header, HTTP::EAcceptCharset, KAcceptCharset ); |
|
634 logstr.Copy(KAcceptCharset); |
|
635 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptCharset = %S", &logstr ); |
|
636 |
|
637 // Set the Accept-Language header as specified in aRequestInfo |
|
638 if ( aRequestInfo.iAcceptLanguage.Length() != 0 ) |
|
639 { |
|
640 SetHeaderL( header, HTTP::EAcceptLanguage, |
|
641 aRequestInfo.iAcceptLanguage ); |
|
642 logstr.Copy(aRequestInfo.iAcceptLanguage); |
|
643 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptLanguage = %S", &logstr ); |
|
644 } |
|
645 // If not specified then set the default accept language as "en" |
|
646 else |
|
647 { |
|
648 SetHeaderL( header, HTTP::EAcceptLanguage, KAcceptLanguage ); |
|
649 logstr.Copy(KAcceptLanguage); |
|
650 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - HTTP::EAcceptLanguage = %S", &logstr ); |
|
651 } |
|
652 |
|
653 // Set the If-Modified-Since header if required |
|
654 if ( aRequestInfo.isIfModifiedSet ) |
|
655 { |
|
656 THTTPHdrVal val( aRequestInfo.iIfModifiedSince ); |
|
657 header.SetFieldL( iHttpSession.StringPool().StringF( |
|
658 HTTP::EIfModifiedSince, RHTTPSession::GetTable() ), val ); |
|
659 } |
|
660 |
|
661 // Set the x-wap-profile header |
|
662 |
|
663 TBuf8<KWapProfileMaxLength> xWapProfile; |
|
664 _LIT(KXWapProfile,"x-wap-profile"); |
|
665 xWapProfile.Copy(KXWapProfile); |
|
666 RStringF xWapProfileString = iHttpSession.StringPool().OpenFStringL( |
|
667 xWapProfile ); |
|
668 RStringF xWapProfileValueString = iHttpSession.StringPool().OpenFStringL( |
|
669 iIRNetworkControllerHandle->GetWapProfString()->Des() ); |
|
670 logstr.Copy(iIRNetworkControllerHandle->GetWapProfString()->Des()); |
|
671 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - x-wap-profile = %S", &logstr ); |
|
672 THTTPHdrVal xWapProfileHeader(xWapProfileValueString ); |
|
673 header.SetFieldL(xWapProfileString, xWapProfileHeader); |
|
674 xWapProfileString.Close(); |
|
675 xWapProfileValueString.Close(); |
|
676 |
|
677 |
|
678 |
|
679 |
|
680 //////////////////////////////////////////////////////////////////////////////// |
|
681 |
|
682 //this piece of code is to get the MIME types supported by a device |
|
683 TInt i,ii,j; |
|
684 CMMFControllerPluginSelectionParameters *cs=CMMFControllerPluginSelectionParameters::NewLC(); |
|
685 CMMFFormatSelectionParameters * fs = CMMFFormatSelectionParameters::NewLC(); |
|
686 cs->SetRequiredPlayFormatSupportL(*fs); |
|
687 cs->SetRequiredRecordFormatSupportL(*fs); |
|
688 |
|
689 RMMFControllerImplInfoArray controllers; |
|
690 CleanupResetAndDestroyPushL(controllers); |
|
691 cs->ListImplementationsL(controllers); |
|
692 |
|
693 TInt contrCount = controllers.Count(); |
|
694 RBuf8 audioMIMEs; |
|
695 audioMIMEs.Create(KSize); |
|
696 RBuf audioBuf; |
|
697 audioBuf.Create(KBufSize); |
|
698 _LIT(KAudio,"audio"); |
|
699 audioBuf.Copy(KAudio); |
|
700 for(i=0;i<controllers.Count();i++) |
|
701 { |
|
702 if( KUidHelixController == controllers[i]->Uid() ) |
|
703 { |
|
704 //supported play formats |
|
705 const RMMFFormatImplInfoArray &pf=controllers[i]->PlayFormats(); |
|
706 TInt pfCount = pf.Count(); |
|
707 for(ii=0;ii<pf.Count();ii++) |
|
708 { |
|
709 TBuf<KSize> z; |
|
710 TBuf<KSize> z1; |
|
711 TBool first; |
|
712 //file extensions |
|
713 const CDesC8Array &fe=pf[ii]->SupportedFileExtensions(); |
|
714 first=TRUE; |
|
715 z1.Zero(); |
|
716 for(j=0;j<fe.Count();j++) |
|
717 { |
|
718 _LIT(KNone,", "); |
|
719 if(!first)z1.Append(KNone); |
|
720 first=FALSE; |
|
721 z.Copy(fe[j]); |
|
722 z1.Append(z); |
|
723 }; |
|
724 |
|
725 //MIME types |
|
726 const CDesC8Array &mt=pf[ii]->SupportedMimeTypes(); |
|
727 first=TRUE; |
|
728 z1.Zero(); |
|
729 TInt tempD = 0; |
|
730 for(j=0;j<mt.Count();j++) |
|
731 { |
|
732 z.Copy(mt[j]); |
|
733 TInt res = z.Find(audioBuf); |
|
734 if(res != KErrNotFound) |
|
735 { |
|
736 if(!first) |
|
737 { |
|
738 _LIT(KNone,", "); |
|
739 z1.Append(KNone); |
|
740 } |
|
741 first=FALSE; |
|
742 z1.Append(z); |
|
743 audioMIMEs.Append(z); |
|
744 if(j==mt.Count() && ii==pf.Count() && i==controllers.Count() ) |
|
745 { |
|
746 //do nothing |
|
747 } |
|
748 else |
|
749 { |
|
750 _LIT(KComma,","); |
|
751 audioMIMEs.Append(KComma); |
|
752 } |
|
753 tempD++; |
|
754 } |
|
755 }; |
|
756 |
|
757 };// for play formats |
|
758 } |
|
759 |
|
760 }; |
|
761 audioBuf.Close(); |
|
762 CleanupStack::PopAndDestroy(1);//controllers |
|
763 CleanupStack::PopAndDestroy(fs); |
|
764 CleanupStack::PopAndDestroy(cs); |
|
765 |
|
766 |
|
767 ///////////////////////////////////////////////////////////////////////////////// |
|
768 |
|
769 |
|
770 |
|
771 // Set the X-Nokia-iRAPP-Accept header |
|
772 |
|
773 TBuf8<KNokiaIrAppAcceptMaxLength> xNokiaIrAppAccept; |
|
774 _LIT(KXNokiaIrAppAccept,"X-Nokia-iRAPP-Accept"); |
|
775 xNokiaIrAppAccept.Copy(KXNokiaIrAppAccept); |
|
776 RStringF xNokiaIrAppAcceptString = iHttpSession.StringPool().OpenFStringL( |
|
777 xNokiaIrAppAccept ); |
|
778 RStringF xNokiaIrAppAcceptValueString = iHttpSession.StringPool().OpenFStringL( |
|
779 audioMIMEs ); |
|
780 logstr.Copy(audioMIMEs); |
|
781 IRLOG_DEBUG2( "CIRHttpDataProvider::BuildHeadersL - X-Nokia-iRAPP-Accept = %S", &logstr ); |
|
782 THTTPHdrVal xNokiaIrAppAcceptHeader(xNokiaIrAppAcceptValueString ); |
|
783 header.SetFieldL(xNokiaIrAppAcceptString, xNokiaIrAppAcceptHeader); |
|
784 xNokiaIrAppAcceptString.Close(); |
|
785 xNokiaIrAppAcceptValueString.Close(); |
|
786 |
|
787 |
|
788 audioMIMEs.Close(); |
|
789 |
|
790 CleanupStack::PopAndDestroy(&logstr); |
|
791 IRLOG_DEBUG( "CIRHttpDataProvider::BuildHeadersL - Exiting." ); |
|
792 } |
|
793 |
|
794 // --------------------------------------------------------------------------- |
|
795 // CIRHttpDataProvider::ValidateStatusCode(TInt aStatusCode) |
|
796 // Validate the status code returned |
|
797 // --------------------------------------------------------------------------- |
|
798 // |
|
799 void CIRHttpDataProvider::ValidateStatusCode( TInt aStatusCode ) |
|
800 { |
|
801 IRLOG_DEBUG( "CIRHttpDataProvider::ValidateStatusCode- Entering" ); |
|
802 // Callbacks will be provided as and when the call handling in UI is ready |
|
803 switch ( aStatusCode ) |
|
804 { |
|
805 case KOk: |
|
806 { |
|
807 } |
|
808 break; |
|
809 |
|
810 case KCreated: |
|
811 { |
|
812 } |
|
813 break; |
|
814 |
|
815 case KAccepted: |
|
816 { |
|
817 } |
|
818 break; |
|
819 |
|
820 case KNonAuthoritativeInformation: |
|
821 { |
|
822 } |
|
823 break; |
|
824 |
|
825 case KNoContent: |
|
826 { |
|
827 } |
|
828 break; |
|
829 |
|
830 case KResetContent: |
|
831 { |
|
832 } |
|
833 break; |
|
834 |
|
835 case KPartialContent: |
|
836 { |
|
837 } |
|
838 break; |
|
839 |
|
840 /* |
|
841 Redirection 3xx status codes |
|
842 */ |
|
843 case KMultipleChoices: |
|
844 { |
|
845 } |
|
846 break; |
|
847 |
|
848 case KMovedPermanently: |
|
849 { |
|
850 } |
|
851 break; |
|
852 |
|
853 case KFound: |
|
854 { |
|
855 } |
|
856 break; |
|
857 |
|
858 case KSeeOther: |
|
859 { |
|
860 } |
|
861 break; |
|
862 |
|
863 case KNotModified: |
|
864 { |
|
865 iNotModified = ETrue; |
|
866 iObserver.HttpResponseCodeRecieved( KNotModified ); |
|
867 } |
|
868 break; |
|
869 |
|
870 case KUseProxy: |
|
871 { |
|
872 } |
|
873 break; |
|
874 |
|
875 /* |
|
876 This status code is not used as per RFC 2616 |
|
877 const TInt KUnused = 306 |
|
878 */ |
|
879 case KTemporaryRedirect: |
|
880 { |
|
881 } |
|
882 break; |
|
883 |
|
884 /* |
|
885 Client Error 4xx status codes |
|
886 */ |
|
887 case KBadRequest: |
|
888 { |
|
889 } |
|
890 break; |
|
891 |
|
892 case KUnauthorized: |
|
893 { |
|
894 } |
|
895 break; |
|
896 |
|
897 case KPaymentRequired: |
|
898 { |
|
899 } |
|
900 break; |
|
901 |
|
902 case KForbidden: |
|
903 { |
|
904 } |
|
905 break; |
|
906 |
|
907 case KNotFound: |
|
908 { |
|
909 iObserver.HttpResponseCodeRecieved( KNotFound ); |
|
910 } |
|
911 break; |
|
912 |
|
913 case KMethodNotAllowed: |
|
914 { |
|
915 } |
|
916 break; |
|
917 |
|
918 case KNotAcceptable: |
|
919 { |
|
920 } |
|
921 break; |
|
922 |
|
923 case KProxyAuthenticationRequired: |
|
924 { |
|
925 } |
|
926 break; |
|
927 |
|
928 case KRequestTimeout: |
|
929 { |
|
930 } |
|
931 break; |
|
932 |
|
933 case KConflict: |
|
934 { |
|
935 } |
|
936 break; |
|
937 |
|
938 case KGone: |
|
939 { |
|
940 } |
|
941 break; |
|
942 |
|
943 case KLengthRequired: |
|
944 { |
|
945 } |
|
946 break; |
|
947 |
|
948 case KPreconditionFailed: |
|
949 { |
|
950 } |
|
951 break; |
|
952 |
|
953 case KRequestEntityTooLarge: |
|
954 { |
|
955 } |
|
956 break; |
|
957 |
|
958 case KRequestURITooLong: |
|
959 { |
|
960 } |
|
961 break; |
|
962 |
|
963 case KUnsupportedMediaType: |
|
964 { |
|
965 } |
|
966 break; |
|
967 |
|
968 case KRequestedRangeNotSatisfiable: |
|
969 { |
|
970 } |
|
971 break; |
|
972 |
|
973 case KExpectationFailed: |
|
974 { |
|
975 } |
|
976 break; |
|
977 |
|
978 /* |
|
979 Server Error 5xx status codes |
|
980 */ |
|
981 case KInternalServerError: |
|
982 { |
|
983 } |
|
984 break; |
|
985 |
|
986 case KNotImplemented: |
|
987 { |
|
988 } |
|
989 break; |
|
990 |
|
991 case KBadGateway: |
|
992 { |
|
993 } |
|
994 break; |
|
995 |
|
996 case KServiceUnavailable: |
|
997 { |
|
998 } |
|
999 break; |
|
1000 |
|
1001 case KGatewayTimeout: |
|
1002 { |
|
1003 } |
|
1004 break; |
|
1005 |
|
1006 case KHTTPVersionNotSupported: |
|
1007 { |
|
1008 } |
|
1009 break; |
|
1010 |
|
1011 default: |
|
1012 break; |
|
1013 |
|
1014 } // End of switch(aStatusCode) |
|
1015 IRLOG_DEBUG( "CIRHttpDataProvider::ValidateStatusCode - Exiting." ); |
|
1016 } // ValidateStatusCode(TInt aStatusCode) |
|
1017 |
|
1018 |
|
1019 // --------------------------------------------------------------------------- |
|
1020 // CIRHttpDataProvider::ReleaseResources() |
|
1021 // Used to free all resources |
|
1022 // --------------------------------------------------------------------------- |
|
1023 // |
|
1024 void CIRHttpDataProvider::ReleaseResources() |
|
1025 { |
|
1026 IRLOG_DEBUG( "CIRHttpDataProvider::ReleaseResources - Entering" ); |
|
1027 iLogoDownloadEngine->ReleaseResources(); |
|
1028 CancelTransaction(); |
|
1029 iHttpSession.Close(); |
|
1030 iFirstTime = ETrue; |
|
1031 IRLOG_DEBUG( "CIRHttpDataProvider::ReleaseResources - Exiting." ); |
|
1032 } |
|
1033 |
|
1034 |
|
1035 |
|
1036 |