|
1 /* |
|
2 * Copyright (c) 2002-2008 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: Http interface for RoapHandler |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 // INCLUDE FILES |
|
20 #include <stringpool.h> |
|
21 #include <http/thttphdrval.h> |
|
22 #include <HttpFilterCommonStringsExt.h> |
|
23 |
|
24 #include "RoapHttpHandler.h" |
|
25 #include "RoapObserver.h" |
|
26 #include "RoapDef.h" |
|
27 #include "RoapLog.h" |
|
28 |
|
29 //#include <CookieFilterInterface.h> |
|
30 //#include <uaproffilter_interface.h> |
|
31 //#include <HttpFilterProxyInterface.h> |
|
32 #include <httpfilteriopinterface.h> |
|
33 |
|
34 |
|
35 using namespace Roap; |
|
36 |
|
37 // ================= CONSTANTS ====================== |
|
38 |
|
39 // The time out value in HTTP, 30 sec |
|
40 LOCAL_D const TInt KRoapTimeoutValue = 60000000; |
|
41 |
|
42 _LIT8( KTestUserName, "iopvf" ); |
|
43 _LIT8( KTestPassword, "r72005" ); |
|
44 /* |
|
45 _LIT8( KTestUserName, "moria" ); |
|
46 _LIT8( KTestPassword, "mellon" ); |
|
47 */ |
|
48 |
|
49 // ================= MEMBER FUNCTIONS ======================= |
|
50 |
|
51 // --------------------------------------------------------- |
|
52 // CRoapHttpHandler::NewL() |
|
53 // --------------------------------------------------------- |
|
54 // |
|
55 CRoapHttpHandler* CRoapHttpHandler::NewL() |
|
56 { |
|
57 CRoapHttpHandler* handler = new ( ELeave ) CRoapHttpHandler(); |
|
58 CleanupStack::PushL( handler ); |
|
59 handler->ConstructL(); |
|
60 CleanupStack::Pop( handler ); |
|
61 return handler; |
|
62 } |
|
63 |
|
64 // --------------------------------------------------------- |
|
65 // CRoapHttpHandler::~CHttpLoader() |
|
66 // --------------------------------------------------------- |
|
67 // |
|
68 CRoapHttpHandler::~CRoapHttpHandler() |
|
69 { |
|
70 Cancel(); |
|
71 iSession.Close(); // iSession also closes iTransaction |
|
72 delete iRequestBody; |
|
73 delete iUri; |
|
74 delete iBoundary; |
|
75 delete iConnection; |
|
76 delete iTimeout; |
|
77 } |
|
78 |
|
79 // --------------------------------------------------------- |
|
80 // CRoapHttpHandler::ConstructL() |
|
81 // --------------------------------------------------------- |
|
82 // |
|
83 void CRoapHttpHandler::ConstructL() |
|
84 { |
|
85 LOG( _L("CRoapHttpHandler::ConstructL") ); |
|
86 |
|
87 iConnection = CRoapConnection::NewL(); |
|
88 iTimeout = CPeriodic::NewL( CActive::EPriorityUserInput ); |
|
89 } |
|
90 |
|
91 // --------------------------------------------------------- |
|
92 // CRoapHttpHandler::CreateConnectionL() |
|
93 // --------------------------------------------------------- |
|
94 // |
|
95 void CRoapHttpHandler::CreateConnectionL( TRequestStatus* aStatus ) |
|
96 { |
|
97 LOG( _L("CRoapHttpHandler::CreateConnectionL") ); |
|
98 |
|
99 __ASSERT_ALWAYS( iState == EInit || iState == EReady, \ |
|
100 User::Invariant() ); |
|
101 __ASSERT_ALWAYS( iConnection, User::Invariant() ); |
|
102 |
|
103 TUint32 ap; |
|
104 if ( iConnection->IsConnected( ap ) ) |
|
105 { |
|
106 // Already connected |
|
107 User::RequestComplete( iParentStatus, KErrAlreadyExists ); |
|
108 iParentStatus = NULL; |
|
109 return; |
|
110 } |
|
111 |
|
112 if ( iObserver && !iObserver->ConnectionConfL() ) |
|
113 { |
|
114 User::Leave( KErrCancel ); |
|
115 } |
|
116 |
|
117 iParentStatus = aStatus; |
|
118 *iParentStatus = KRequestPending; |
|
119 iState = EStart; |
|
120 TRequestStatus* ownStatus = &iStatus; |
|
121 *ownStatus = KRequestPending; |
|
122 SetActive(); |
|
123 User::RequestComplete( ownStatus, KErrNone ); |
|
124 } |
|
125 |
|
126 // --------------------------------------------------------- |
|
127 // CRoapHttpHandler::IsConnectedL() |
|
128 // --------------------------------------------------------- |
|
129 // |
|
130 void CRoapHttpHandler::SetObserver( MRoapObserver* aRoapObserver ) |
|
131 { |
|
132 LOG( _L("CRoapHttpHandler::SetObserver") ); |
|
133 |
|
134 iObserver = aRoapObserver; |
|
135 } |
|
136 |
|
137 // --------------------------------------------------------- |
|
138 // CRoapHttpHandler::CreateConnectionL() |
|
139 // --------------------------------------------------------- |
|
140 // |
|
141 void CRoapHttpHandler::DoTransactionL( |
|
142 CRoapResponse& aResponse, |
|
143 TDesC8& aReqBody, |
|
144 TRequestStatus* aStatus ) |
|
145 { |
|
146 LOG( _L("CRoapHttpHandler::DoTransactionL1") ); |
|
147 |
|
148 __ASSERT_ALWAYS( iState == EReady, User::Invariant() ); |
|
149 __ASSERT_ALWAYS( !iRequestBody, User::Invariant() ); |
|
150 |
|
151 iRequestBody = aReqBody.AllocL(); |
|
152 iResponse = &aResponse; |
|
153 |
|
154 iParentStatus = aStatus; |
|
155 *iParentStatus = KRequestPending; |
|
156 iState = ERequest; |
|
157 TRequestStatus* ownStatus = &iStatus; |
|
158 *ownStatus = KRequestPending; |
|
159 SetActive(); |
|
160 User::RequestComplete( ownStatus, KErrNone ); |
|
161 } |
|
162 |
|
163 // --------------------------------------------------------- |
|
164 // CRoapHttpHandler::SetUrlL() |
|
165 // --------------------------------------------------------- |
|
166 // |
|
167 void CRoapHttpHandler::SetUrlL( TDesC8& aUrl ) |
|
168 { |
|
169 LOG( _L("CRoapHttpHandler::SetUrlL") ); |
|
170 |
|
171 delete iUri; |
|
172 iUri = NULL; |
|
173 iUri = aUrl.AllocL(); |
|
174 } |
|
175 |
|
176 |
|
177 |
|
178 // --------------------------------------------------------- |
|
179 // CRoapHttpHandler::DoCancel() |
|
180 // --------------------------------------------------------- |
|
181 // |
|
182 void CRoapHttpHandler::DoCancel() |
|
183 { |
|
184 LOG( _L("CRoapHttpHandler::DoCancel") ); |
|
185 |
|
186 switch ( iState ) |
|
187 { |
|
188 case EStart: |
|
189 case EConnect: |
|
190 { |
|
191 iConnection->Cancel(); |
|
192 break; |
|
193 } |
|
194 case EComplete: |
|
195 { |
|
196 iTransaction.Close(); |
|
197 SelfComplete( iError ); |
|
198 break; |
|
199 } |
|
200 default: |
|
201 { |
|
202 break; |
|
203 } |
|
204 } |
|
205 iError = KErrCancel; |
|
206 Complete(); |
|
207 } |
|
208 |
|
209 // --------------------------------------------------------- |
|
210 // CRoapHttpHandler::RunL() |
|
211 // --------------------------------------------------------- |
|
212 // |
|
213 void CRoapHttpHandler::RunL() |
|
214 { |
|
215 LOG( _L("CRoapHttpHandler::RunL") ); |
|
216 |
|
217 User::LeaveIfError( iStatus.Int() ); |
|
218 |
|
219 switch ( iState ) |
|
220 { |
|
221 case EStart: |
|
222 { |
|
223 ConnectL(); |
|
224 break; |
|
225 } |
|
226 case EConnect: |
|
227 { |
|
228 CreateSessionL(); |
|
229 break; |
|
230 } |
|
231 case ERequest: |
|
232 { |
|
233 DoTransactionL(); |
|
234 break; |
|
235 } |
|
236 case EComplete: |
|
237 { |
|
238 TUint32 ap; |
|
239 iState = iConnection->IsConnected( ap ) ? EReady : EInit; |
|
240 Complete(); |
|
241 break; |
|
242 } |
|
243 case EInit: |
|
244 default: |
|
245 { |
|
246 break; |
|
247 } |
|
248 } |
|
249 } |
|
250 |
|
251 // --------------------------------------------------------- |
|
252 // CRoapHttpHandler::RunError() |
|
253 // --------------------------------------------------------- |
|
254 // |
|
255 TInt CRoapHttpHandler::RunError( TInt aError ) |
|
256 { |
|
257 LOG( _L("CRoapHttpHandler::RunError") ); |
|
258 |
|
259 iError = aError; |
|
260 TUint32 ap; |
|
261 iState = iConnection->IsConnected( ap ) ? EReady : EInit; |
|
262 Complete(); |
|
263 return KErrNone; |
|
264 } |
|
265 |
|
266 // --------------------------------------------------------- |
|
267 // CRoapHttpHandler::ConnectL() |
|
268 // --------------------------------------------------------- |
|
269 // |
|
270 void CRoapHttpHandler::ConnectL() |
|
271 { |
|
272 LOG( _L("CRoapHttpHandler::ConnectL") ); |
|
273 |
|
274 __ASSERT_ALWAYS( iState == EStart, User::Invariant() ); |
|
275 |
|
276 iConnection->ConnectL ( iPreferredIap, &iStatus ); |
|
277 iState = EConnect; |
|
278 iError = KErrNone; |
|
279 SetActive(); |
|
280 } |
|
281 |
|
282 // --------------------------------------------------------- |
|
283 // CRoapHttpHandler::SetPreferredIap() |
|
284 // --------------------------------------------------------- |
|
285 void CRoapHttpHandler::SetPreferredIap( TUint32 aPreferredIap ) |
|
286 { |
|
287 LOG( _L("CRoapHttpHandler::SetPreferredIap") ); |
|
288 |
|
289 iPreferredIap = aPreferredIap; |
|
290 } |
|
291 |
|
292 // --------------------------------------------------------- |
|
293 // CRoapHttpHandler::CreateSessionL() |
|
294 // --------------------------------------------------------- |
|
295 // |
|
296 void CRoapHttpHandler::CreateSessionL() |
|
297 { |
|
298 LOG( _L("CRoapHttpHandler::CreateSessionL") ); |
|
299 |
|
300 __ASSERT_ALWAYS( iState == EConnect, User::Invariant() ); |
|
301 |
|
302 TUint32 ap; |
|
303 |
|
304 if ( !iConnection->IsConnected( ap ) ) |
|
305 { |
|
306 User::Leave( KErrRoapGeneral ); |
|
307 } |
|
308 |
|
309 iSession.Close(); |
|
310 iSession.OpenL(); |
|
311 |
|
312 RStringPool strPool = iSession.StringPool(); |
|
313 |
|
314 // Remove first session properties just in case. |
|
315 RHTTPConnectionInfo connInfo = iSession.ConnectionInfo(); |
|
316 |
|
317 // Clear RConnection and Socket Server instances |
|
318 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketServ,RHTTPSession::GetTable())); |
|
319 connInfo.RemoveProperty(strPool.StringF(HTTP::EHttpSocketConnection,RHTTPSession::GetTable())); |
|
320 |
|
321 THTTPHdrVal proxyUsage(strPool.StringF(HTTP::EUseProxy,RHTTPSession::GetTable())); |
|
322 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyUsage,RHTTPSession::GetTable())); |
|
323 connInfo.RemoveProperty(strPool.StringF(HTTP::EProxyAddress,RHTTPSession::GetTable())); |
|
324 |
|
325 connInfo.SetPropertyL |
|
326 ( |
|
327 strPool.StringF( HTTP::EHttpSocketServ, RHTTPSession::GetTable() ), |
|
328 THTTPHdrVal( iConnection->SocketServ().Handle() ) |
|
329 ); |
|
330 |
|
331 connInfo.SetPropertyL |
|
332 ( |
|
333 strPool.StringF( HTTP::EHttpSocketConnection, RHTTPSession::GetTable() ), |
|
334 THTTPHdrVal( REINTERPRET_CAST( TInt, &iConnection->Conn() ) ) |
|
335 ); |
|
336 |
|
337 InstallHttpFiltersL(); |
|
338 |
|
339 // Complete requests |
|
340 iState = EReady; |
|
341 SelfComplete( iError ); |
|
342 // Notify CRoapEngBase |
|
343 Complete(); |
|
344 } |
|
345 |
|
346 |
|
347 // --------------------------------------------------------- |
|
348 // CRoapHttpHandler::InstallHttpFilters() |
|
349 // --------------------------------------------------------- |
|
350 // |
|
351 void CRoapHttpHandler::InstallHttpFiltersL() |
|
352 { |
|
353 LOG( _L("CRoapHttpHandler::InstallHttpFiltersL") ); |
|
354 |
|
355 // CHttpUAProfFilterInterface::InstallFilterL( iSession ); |
|
356 // CHttpCookieFilter::InstallFilterL( iSession ); |
|
357 InstallAuthenticationL( iSession ); |
|
358 // CHttpFilterProxyInterface::InstallFilterL( iSession ); |
|
359 |
|
360 // This filter adds port number to HTTP header Host |
|
361 // on HTTP(S) CONNECT via proxy. |
|
362 // Note: the filter is for interoperability, since some WAP GWs |
|
363 // do not work with Host header not having port number. |
|
364 CHttpFilterIopInterface::InstallFilterL( iSession, iopOptionHostHeader ); |
|
365 } |
|
366 |
|
367 |
|
368 // --------------------------------------------------------- |
|
369 // CRoapHttpHandler::DoTransactionL() |
|
370 // --------------------------------------------------------- |
|
371 // |
|
372 void CRoapHttpHandler::DoTransactionL() |
|
373 { |
|
374 LOG( _L("CRoapHttpHandler::DoTransactionL2") ); |
|
375 |
|
376 __ASSERT_ALWAYS( iState == ERequest, User::Invariant() ); |
|
377 |
|
378 TUriParser8 uri; |
|
379 User::LeaveIfError( uri.Parse( *iUri ) ); |
|
380 RStringF POST; |
|
381 POST = iSession.StringPool().StringF( HTTP::EPOST, RHTTPSession::GetTable() ); |
|
382 iTransaction = iSession.OpenTransactionL( uri, *this, POST ); |
|
383 |
|
384 // Set required headers |
|
385 RHTTPHeaders hdrs = iTransaction.Request().GetHeaderCollection(); |
|
386 |
|
387 SetHeaderL(hdrs, HTTP::EAccept, _L8("*/*") ); // for testing |
|
388 SetHeaderL(hdrs, HTTP::EAccept, KRoapPDUType ); |
|
389 SetHeaderL(hdrs, HTTP::EAccept, KMultipartRelatedType ); |
|
390 |
|
391 SetHeaderL(hdrs, HTTP::EContentType, KRoapPDUType); |
|
392 |
|
393 iBytesReceived = 0; |
|
394 // Add request body |
|
395 MHTTPDataSupplier* ds = this; |
|
396 iTransaction.Request().SetBody(*ds); |
|
397 |
|
398 iTransaction.SubmitL(); |
|
399 |
|
400 iState = EComplete; |
|
401 iStatus = KRequestPending; |
|
402 SetActive(); |
|
403 |
|
404 iTimeout->Cancel(); |
|
405 iTimeout->Start( KRoapTimeoutValue, |
|
406 KRoapTimeoutValue, |
|
407 TCallBack( StaticTimeOut,this ) ); |
|
408 } |
|
409 |
|
410 |
|
411 // --------------------------------------------------------- |
|
412 // CRoapHttpHandler::SetHeaderL() |
|
413 // --------------------------------------------------------- |
|
414 // |
|
415 void CRoapHttpHandler::SetHeaderL(RHTTPHeaders aHeaders, TInt aHdrField, const TDesC8& aHdrValue) |
|
416 { |
|
417 LOG( _L("CRoapHttpHandler::SetHeaderL") ); |
|
418 |
|
419 RStringF valStr = iSession.StringPool().OpenFStringL(aHdrValue); |
|
420 THTTPHdrVal val(valStr); |
|
421 aHeaders.SetFieldL(iSession.StringPool().StringF(aHdrField,RHTTPSession::GetTable()), val); |
|
422 valStr.Close(); |
|
423 } |
|
424 |
|
425 |
|
426 // --------------------------------------------------------- |
|
427 // CRoapHttpHandler::Complete() |
|
428 // --------------------------------------------------------- |
|
429 // |
|
430 void CRoapHttpHandler::Complete() |
|
431 { |
|
432 LOG( _L("CRoapHttpHandler::Complete") ); |
|
433 |
|
434 delete iRequestBody; |
|
435 iRequestBody = NULL; |
|
436 delete iUri; |
|
437 iUri = NULL; |
|
438 |
|
439 if ( iTimeout ) |
|
440 { |
|
441 iTimeout->Cancel(); |
|
442 } |
|
443 |
|
444 User::RequestComplete( iParentStatus, iError ); |
|
445 iParentStatus = NULL; |
|
446 } |
|
447 |
|
448 |
|
449 // --------------------------------------------------------- |
|
450 // CRoapHttpHandler::CRoapHttpHandler() |
|
451 // --------------------------------------------------------- |
|
452 // |
|
453 CRoapHttpHandler::CRoapHttpHandler(): CActive( CActive::EPriorityStandard ) |
|
454 { |
|
455 CActiveScheduler::Add( this ); |
|
456 } |
|
457 |
|
458 |
|
459 // --------------------------------------------------------- |
|
460 // CRoapHttpHandler::SelfComplete() |
|
461 // --------------------------------------------------------- |
|
462 // |
|
463 void CRoapHttpHandler::SelfComplete( TInt& aResult ) |
|
464 { |
|
465 LOG( _L("CRoapHttpHandler::SelfComplete") ); |
|
466 |
|
467 if ( iStatus == KRequestPending ) |
|
468 { |
|
469 TRequestStatus* ownStatus = &iStatus; |
|
470 User::RequestComplete( ownStatus, aResult ); |
|
471 } |
|
472 else |
|
473 { |
|
474 if ( aResult != KErrNone ) |
|
475 { |
|
476 iStatus = aResult; |
|
477 } |
|
478 } |
|
479 } |
|
480 |
|
481 |
|
482 // --------------------------------------------------------- |
|
483 // CRoapHttpHandler::MHFRunL() |
|
484 // --------------------------------------------------------- |
|
485 // |
|
486 void CRoapHttpHandler::MHFRunL( RHTTPTransaction /* aTransaction */, |
|
487 const THTTPEvent& aEvent ) |
|
488 { |
|
489 LOG( _L("CRoapHttpHandler::MHFRunL") ); |
|
490 |
|
491 // Restart timer |
|
492 iTimeout->Cancel(); |
|
493 iTimeout->Start( KRoapTimeoutValue, |
|
494 KRoapTimeoutValue, |
|
495 TCallBack( StaticTimeOut,this ) ); |
|
496 |
|
497 switch ( aEvent.iStatus ) |
|
498 { |
|
499 case THTTPEvent::EGotResponseHeaders: |
|
500 { |
|
501 LOG( _L("Got Response Headers!") ); |
|
502 |
|
503 HandleResponseHeadersL( iTransaction.Response() ); |
|
504 break; |
|
505 } |
|
506 |
|
507 case THTTPEvent::EGotResponseBodyData: |
|
508 { |
|
509 LOG( _L("Got Response Body Data!") ); |
|
510 |
|
511 TInt ret( KErrNone ); |
|
512 MHTTPDataSupplier* body = iTransaction.Response().Body(); |
|
513 TPtrC8 ptr; |
|
514 body->GetNextDataPart( ptr ); |
|
515 |
|
516 iBytesReceived += ptr.Length(); |
|
517 if ( iResponse->iDataType == TDataType( KMultipartRelatedType ) ) |
|
518 { |
|
519 ret = AppendMultipartData( ptr ); |
|
520 } |
|
521 else |
|
522 { |
|
523 ret = AppendPduData( ptr ); |
|
524 } |
|
525 |
|
526 if ( iObserver && iReportBytes ) |
|
527 { |
|
528 iObserver->RoapProgressInfoL( KRoapProgressMax + iBytesReceived ); |
|
529 } |
|
530 |
|
531 body->ReleaseData(); |
|
532 User::LeaveIfError( ret ); |
|
533 break; |
|
534 } |
|
535 |
|
536 case THTTPEvent::EFailed: |
|
537 { |
|
538 LOG( _L("HTTP Event Failed!") ); |
|
539 if ( iResponse->iDataType == TDataType( KMultipartRelatedType ) ) |
|
540 { |
|
541 } |
|
542 if ( iError == KErrNone ) |
|
543 { |
|
544 iError = KErrRoapGeneral; |
|
545 } |
|
546 iTransaction.Close(); |
|
547 SelfComplete( iError ); |
|
548 break; |
|
549 } |
|
550 |
|
551 case THTTPEvent::ESucceeded: |
|
552 { |
|
553 LOG( _L("HTTP Event Succeeded!") ); |
|
554 |
|
555 if ( iResponse->iDataType == TDataType( KMultipartRelatedType ) ) |
|
556 { |
|
557 } |
|
558 iTransaction.Close(); |
|
559 SelfComplete( iError ); |
|
560 break; |
|
561 } |
|
562 |
|
563 case THTTPEvent::ERedirectRequiresConfirmation: |
|
564 { |
|
565 LOG( _L("HTTP event ERedirectRequiresConfirmation received") ); |
|
566 iTransaction.SubmitL(); |
|
567 } |
|
568 |
|
569 default: |
|
570 { |
|
571 LOG( _L("Unknown HTTP event recieved") ); |
|
572 if ( aEvent.iStatus == KErrHttpRedirectUseProxy ) |
|
573 { |
|
574 } |
|
575 else |
|
576 { |
|
577 if (aEvent.iStatus < 0) |
|
578 { |
|
579 LOG( _L("An Error Occured during HTTP transaction!") ); |
|
580 } |
|
581 // Handle errors in MHFRunError. |
|
582 User::LeaveIfError( aEvent.iStatus ); |
|
583 } |
|
584 break; |
|
585 } |
|
586 } |
|
587 |
|
588 } |
|
589 |
|
590 // --------------------------------------------------------- |
|
591 // CRoapHttpHandler::MHFRunError() |
|
592 // --------------------------------------------------------- |
|
593 // |
|
594 TInt CRoapHttpHandler::MHFRunError ( |
|
595 TInt aError, |
|
596 RHTTPTransaction /* aTransaction */, |
|
597 const THTTPEvent& /* aEvent */ |
|
598 ) |
|
599 { |
|
600 LOG( _L("CRoapHttpHandler::MHFRunError") ); |
|
601 |
|
602 iTransaction.Close(); |
|
603 iError = aError; |
|
604 SelfComplete( iError ); |
|
605 return KErrNone; |
|
606 } |
|
607 |
|
608 // --------------------------------------------------------- |
|
609 // CRoapHttpHandler::HandleResponseHeadersL() |
|
610 // --------------------------------------------------------- |
|
611 // |
|
612 void CRoapHttpHandler::HandleResponseHeadersL( RHTTPResponse aHttpResponse ) |
|
613 { |
|
614 LOG( _L("CRoapHttpHandler::HandleResponseHeadersL ->") ); |
|
615 |
|
616 RHTTPHeaders headers = aHttpResponse.GetHeaderCollection(); |
|
617 |
|
618 TInt httpCode = aHttpResponse.StatusCode(); |
|
619 TBool status; |
|
620 |
|
621 status = CheckHttpCode( httpCode ); |
|
622 |
|
623 if ( status ) |
|
624 { |
|
625 RStringF contentTypeStr; |
|
626 RStringF boundaryStr; |
|
627 THTTPHdrVal contentTypeVal; |
|
628 THTTPHdrVal boundaryVal; |
|
629 TPtrC8 ptrContentType(KNullDesC8); |
|
630 RStringPool srtPool; |
|
631 srtPool = iSession.StringPool(); |
|
632 |
|
633 contentTypeStr = srtPool.StringF( HTTP::EContentType, RHTTPSession::GetTable() ); |
|
634 |
|
635 User::LeaveIfError( headers.GetField( contentTypeStr, 0, contentTypeVal ) ); |
|
636 |
|
637 if ( contentTypeVal.Type() == THTTPHdrVal::KStrFVal ) |
|
638 { |
|
639 iResponse->iDataType = TDataType( contentTypeVal.StrF().DesC() ); |
|
640 } |
|
641 |
|
642 if ( iResponse->iDataType == TDataType( KMultipartRelatedType ) ) |
|
643 { |
|
644 TPath tempPath; |
|
645 TFileName fileName; |
|
646 TInt maxSize( 0 ); |
|
647 |
|
648 if ( iObserver ) |
|
649 { |
|
650 iObserver->ContentDownloadInfoL( tempPath, fileName, maxSize ); |
|
651 } |
|
652 |
|
653 boundaryStr = srtPool.StringF( HttpFilterCommonStringsExt::EBoundary, |
|
654 HttpFilterCommonStringsExt::GetTable() ); |
|
655 |
|
656 if ( headers.GetParam( contentTypeStr, boundaryStr, boundaryVal ) == KErrNone ) |
|
657 { |
|
658 // Boundary param found |
|
659 delete iBoundary; |
|
660 iBoundary = NULL; |
|
661 iBoundary = boundaryVal.StrF().DesC().AllocL(); |
|
662 } |
|
663 else |
|
664 { |
|
665 // a multipart without boundary param |
|
666 LOG( _L("Error: multipart boundary missing") ); |
|
667 User::Leave( KErrRoapGeneral ); |
|
668 } |
|
669 iResponse->SetDcfPathL( tempPath ); |
|
670 iResponse->SetContentNameL( fileName ); |
|
671 iReportBytes = ETrue; |
|
672 |
|
673 if ( iObserver ) |
|
674 { |
|
675 iObserver->RoapProgressInfoL( KRoapProgressMax ); |
|
676 } |
|
677 } |
|
678 else |
|
679 { |
|
680 iReportBytes = EFalse; |
|
681 } |
|
682 |
|
683 LOG( iResponse->iDataType.Des() ); |
|
684 |
|
685 if ( iResponse->iDataType != TDataType( KRoapPDUType ) && |
|
686 iResponse->iDataType != TDataType( KMultipartRelatedType ) ) |
|
687 { |
|
688 LOG( _L("Response type not supported") ); |
|
689 User::Leave( KErrRoapUnsupported ); |
|
690 } |
|
691 |
|
692 if ( aHttpResponse.HasBody() && |
|
693 iResponse->iDataType == TDataType( KRoapPDUType ) ) |
|
694 { |
|
695 // Allocate memory for Response PDU |
|
696 TInt dataSize = aHttpResponse.Body()->OverallDataSize(); |
|
697 if ( dataSize >= 0 ) |
|
698 { |
|
699 HBufC8* buf = HBufC8::NewL( dataSize ); |
|
700 delete iResponse->iPdu; |
|
701 iResponse->iPdu = buf; |
|
702 } |
|
703 } |
|
704 } |
|
705 LOG( _L("-> CRoapHttpHandler::HandleResponseHeadersL") ); |
|
706 } |
|
707 |
|
708 |
|
709 // --------------------------------------------------------- |
|
710 // CRoapHttpHandler::CheckHttpCode() |
|
711 // --------------------------------------------------------- |
|
712 // |
|
713 TBool CRoapHttpHandler::CheckHttpCode( TInt aHttpStatus ) |
|
714 { |
|
715 RBuf logBuffer; |
|
716 logBuffer.CleanupClosePushL(); |
|
717 logBuffer.CreateL( KMaxPath ); |
|
718 LOG( _L( "CRoapHttpHandler::CheckHttpCode") ); |
|
719 logBuffer.Append( _L( "HTTP status code: ") ); |
|
720 logBuffer.AppendNum( aHttpStatus ); |
|
721 LOG( logBuffer ); |
|
722 CleanupStack::PopAndDestroy( &logBuffer ); |
|
723 |
|
724 if ( HTTPStatus::IsInformational( aHttpStatus ) ) |
|
725 { |
|
726 // 1xx |
|
727 // Informational messages. |
|
728 iError = KErrNone; |
|
729 return EFalse; |
|
730 } |
|
731 else if ( aHttpStatus == HTTPStatus::EOk || |
|
732 aHttpStatus == HTTPStatus::ENonAuthoritativeInfo ) |
|
733 { |
|
734 // 200 OK |
|
735 // 203 Non-Authoritative Information |
|
736 iError = KErrNone; |
|
737 return ETrue; |
|
738 } |
|
739 else if ( HTTPStatus::IsSuccessful( aHttpStatus ) ) |
|
740 { |
|
741 // 2xx |
|
742 // Success codes without an usable body. |
|
743 iError = KErrRoapServer; |
|
744 return EFalse; |
|
745 } |
|
746 // 3xx codes handled by redirect filter. |
|
747 else if ( aHttpStatus == HTTPStatus::EUnauthorized || |
|
748 aHttpStatus == HTTPStatus::EProxyAuthenticationRequired ) |
|
749 { |
|
750 // 401 Unauthorized |
|
751 // 407 Proxy authentication required |
|
752 iError = KErrRoapGeneral; |
|
753 return EFalse; |
|
754 } |
|
755 else if ( aHttpStatus == HTTPStatus::ENotFound || |
|
756 aHttpStatus == HTTPStatus::EGone ) |
|
757 { |
|
758 // 404 Not found |
|
759 // 410 Gone |
|
760 iError = KErrRoapGeneral; |
|
761 return EFalse; |
|
762 } |
|
763 else if ( HTTPStatus::IsClientError( aHttpStatus ) ) |
|
764 { |
|
765 // 4xx |
|
766 iError = KErrRoapDevice; |
|
767 return EFalse; |
|
768 } |
|
769 else if ( aHttpStatus == HTTPStatus::EHTTPVersionNotSupported ) |
|
770 { |
|
771 // 505 HTTP Version Not Supported |
|
772 // Retry with lower HTTP version if we can. |
|
773 iError = /*VersionRetryL() ? KErrNone :*/ KErrRoapServer; |
|
774 return EFalse; |
|
775 } |
|
776 else if ( HTTPStatus::IsServerError( aHttpStatus ) ) |
|
777 { |
|
778 // 5xx |
|
779 // HTTP/1.0 servers may return other 5xx error codes for HTTP/1.1 |
|
780 // requests. So the same treatment is given for all 5xx errors |
|
781 // (version retry) - it's worth a try. |
|
782 iError = /* VersionRetryL() ? KErrNone :*/ KErrRoapServer; |
|
783 return EFalse; |
|
784 } |
|
785 else |
|
786 { |
|
787 // Everything else. |
|
788 iError = KErrRoapGeneral; |
|
789 } |
|
790 return EFalse; |
|
791 } |
|
792 |
|
793 |
|
794 // --------------------------------------------------------- |
|
795 // CRoapHttpHandler::AppendData() |
|
796 // --------------------------------------------------------- |
|
797 // |
|
798 TInt CRoapHttpHandler::AppendPduData( const TDesC8& aDataChunk ) |
|
799 { |
|
800 LOG( _L("CRoapHttpHandler::AppendData") ); |
|
801 |
|
802 TInt needed = iResponse->iPdu->Des().Length() + aDataChunk.Length(); |
|
803 if ( iResponse->iPdu->Des().MaxLength() < needed ) |
|
804 { |
|
805 HBufC8* buf = iResponse->iPdu->ReAlloc( needed ); |
|
806 if ( buf ) |
|
807 { |
|
808 iResponse->iPdu = buf; |
|
809 } |
|
810 else |
|
811 { |
|
812 return KErrNoMemory; |
|
813 } |
|
814 } |
|
815 iResponse->iPdu->Des().Append( aDataChunk ); |
|
816 return KErrNone; |
|
817 } |
|
818 |
|
819 |
|
820 // --------------------------------------------------------- |
|
821 // CRoapHttpHandler::AppendMultipartData() |
|
822 // --------------------------------------------------------- |
|
823 // |
|
824 TInt CRoapHttpHandler::AppendMultipartData( const TDesC8& aDataChunk ) |
|
825 { |
|
826 // LOG( _L("CRoapHttpHandler::AppendMultipartData") ); |
|
827 TInt r = KErrNone; |
|
828 TRAP( r, iResponse->AppendMultipartDataL( aDataChunk ) ); |
|
829 return r; |
|
830 } |
|
831 |
|
832 |
|
833 // ----------------------------------------------------------------------------- |
|
834 // CRoapHttpHandler::StaticTimeOut() |
|
835 // ----------------------------------------------------------------------------- |
|
836 // |
|
837 TInt CRoapHttpHandler::StaticTimeOut( TAny* aPointer ) |
|
838 { |
|
839 CRoapHttpHandler* itself = STATIC_CAST(CRoapHttpHandler*, aPointer); |
|
840 if ( itself ) |
|
841 { |
|
842 itself->TimeOut(); |
|
843 } |
|
844 return KErrNone; |
|
845 } |
|
846 |
|
847 |
|
848 // ----------------------------------------------------------------------------- |
|
849 // CRoapHttpHandler::TimeOut() |
|
850 // ----------------------------------------------------------------------------- |
|
851 // |
|
852 void CRoapHttpHandler::TimeOut() |
|
853 { |
|
854 LOG( _L("CRoapHttpHandler::TimeOut") ); |
|
855 |
|
856 iTransaction.Close(); |
|
857 iError = KErrTimedOut; |
|
858 SelfComplete( iError ); |
|
859 } |
|
860 |
|
861 |
|
862 // --------------------------------------------------------- |
|
863 // CRoapHttpHandler::GetNextDataPart() |
|
864 // --------------------------------------------------------- |
|
865 // |
|
866 TBool CRoapHttpHandler::GetNextDataPart( TPtrC8& aDataPart ) |
|
867 { |
|
868 LOG( _L("CRoapHttpHandler::GetNextDataPart") ); |
|
869 |
|
870 aDataPart.Set( iRequestBody->Des() ); |
|
871 return ETrue; |
|
872 } |
|
873 |
|
874 // --------------------------------------------------------- |
|
875 // CRoapHttpHandler::ReleaseData() |
|
876 // --------------------------------------------------------- |
|
877 // |
|
878 void CRoapHttpHandler::ReleaseData() |
|
879 { |
|
880 LOG( _L("CRoapHttpHandler::ReleaseData") ); |
|
881 } |
|
882 |
|
883 // --------------------------------------------------------- |
|
884 // CRoapHttpHandler::OverallDataSize() |
|
885 // --------------------------------------------------------- |
|
886 // |
|
887 TInt CRoapHttpHandler::OverallDataSize() |
|
888 { |
|
889 LOG( _L("CRoapHttpHandler::OverallDataSize") ); |
|
890 |
|
891 return iRequestBody->Des().Size(); |
|
892 } |
|
893 |
|
894 // --------------------------------------------------------- |
|
895 // CRoapHttpHandler::Reset() |
|
896 // --------------------------------------------------------- |
|
897 // |
|
898 TInt CRoapHttpHandler::Reset() |
|
899 { |
|
900 LOG( _L("CRoapHttpHandler::Reset") ); |
|
901 |
|
902 return KErrNone; |
|
903 } |
|
904 |
|
905 |
|
906 // --------------------------------------------------------- |
|
907 // CRoapHttpHandler::GetCredentialsL() |
|
908 // --------------------------------------------------------- |
|
909 // |
|
910 TBool CRoapHttpHandler::GetCredentialsL |
|
911 ( |
|
912 const TUriC8& /*aURI*/, |
|
913 RString /*aRealm*/, |
|
914 RStringF aAuthenticationType, |
|
915 RString& aUsername, |
|
916 RString& aPassword |
|
917 ) |
|
918 { |
|
919 LOG( _L( "CRoapHttpHandler::GetCredentialsL") ); |
|
920 TBuf8<64> b; |
|
921 |
|
922 HBufC8* username = NULL; |
|
923 HBufC8* password = NULL; |
|
924 |
|
925 b.Copy(aAuthenticationType.DesC()); |
|
926 LOG(b); |
|
927 |
|
928 username = KTestUserName().AllocLC(); |
|
929 aUsername = iSession.StringPool().OpenStringL( *username ); |
|
930 CleanupStack::PopAndDestroy( username ); |
|
931 |
|
932 password = KTestPassword().AllocLC(); |
|
933 aPassword = iSession.StringPool().OpenStringL( *password ); |
|
934 CleanupStack::PopAndDestroy( password ); |
|
935 |
|
936 return ETrue; |
|
937 } |