|
1 /* |
|
2 * Copyright (c) 2003 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: CXcapHttpRequest |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 // INCLUDE FILES |
|
22 #include <hal.h> |
|
23 #include <e32math.h> |
|
24 #include "XdmCredentials.h" |
|
25 #include "XcapHttpRequest.h" |
|
26 #include "XcapHttpResponse.h" |
|
27 #include "XcapHttpTransport.h" |
|
28 #include "XcapHttpHeaderModel.h" |
|
29 #include "XcapHttpAuthManager.h" |
|
30 #include "XcapHttpRequestTimer.h" |
|
31 |
|
32 // ================= MEMBER FUNCTIONS ======================= |
|
33 // |
|
34 |
|
35 // ---------------------------------------------------------- |
|
36 // CXcapHttpRequest::CXcapHttpRequest |
|
37 // |
|
38 // ---------------------------------------------------------- |
|
39 // |
|
40 CXcapHttpRequest::CXcapHttpRequest( RHTTPSession& aHttpSession, |
|
41 CXcapHttpAuthManager& aAuthManager, |
|
42 CXcapHttpTransport& aTransportMain ) : |
|
43 iHttpSession( aHttpSession ), |
|
44 iTransportMain( aTransportMain ), |
|
45 iSent( EFalse ), |
|
46 iActive( EFalse ), |
|
47 iCancelled( EFalse ), |
|
48 iConstructed( EFalse ), |
|
49 iAuthManager( aAuthManager ) |
|
50 |
|
51 { |
|
52 } |
|
53 |
|
54 // ---------------------------------------------------------- |
|
55 // CXcapHttpRequest::BaseConstructL |
|
56 // |
|
57 // ---------------------------------------------------------- |
|
58 // |
|
59 void CXcapHttpRequest::BaseConstructL( const TDesC& aRequestUri ) |
|
60 { |
|
61 SetRequestUriL( aRequestUri ); |
|
62 iHttpResponse = CXcapHttpResponse::NewL( this, iTransportMain ); |
|
63 iResponseBuffer = CBufSeg::NewL( 250 ); |
|
64 } |
|
65 |
|
66 // ---------------------------------------------------------- |
|
67 // CXcapHttpRequest::~CXcapHttpRequest |
|
68 // |
|
69 // ---------------------------------------------------------- |
|
70 // |
|
71 CXcapHttpRequest::~CXcapHttpRequest() |
|
72 { |
|
73 #ifdef _DEBUG |
|
74 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::~CXcapHttpRequest()" ) ); |
|
75 #endif |
|
76 delete iExpiryTimer; |
|
77 delete iHttpResponse; |
|
78 delete iRequestUriBuf; |
|
79 ReleaseResponseData(); |
|
80 delete iResponseBuffer; |
|
81 delete iWholeUri; |
|
82 iHeaderCollection.Close(); |
|
83 } |
|
84 |
|
85 // ---------------------------------------------------------- |
|
86 // CXcapHttpRequest::DispatchRequestL |
|
87 // |
|
88 // ---------------------------------------------------------- |
|
89 // |
|
90 EXPORT_C void CXcapHttpRequest::DispatchRequestL( TRequestStatus& aClientStatus ) |
|
91 { |
|
92 #ifdef _DEBUG |
|
93 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::DispatchMessageL()" ) ); |
|
94 iSendTime = TimeL(); |
|
95 #endif |
|
96 ConstructRequestL(); |
|
97 DoSetHeadersL(); |
|
98 iCurrentDataLength = 0; |
|
99 aClientStatus = KRequestPending; |
|
100 iClientStatus = &aClientStatus; |
|
101 iHttpTransaction.SubmitL(); |
|
102 SetStatus( ETrue ); |
|
103 iActive = ETrue; |
|
104 } |
|
105 |
|
106 // ---------------------------------------------------------- |
|
107 // CXcapHttpRequest::ConstructRequest |
|
108 // |
|
109 // ---------------------------------------------------------- |
|
110 // |
|
111 void CXcapHttpRequest::ConstructRequestL() |
|
112 { |
|
113 #ifdef _DEBUG |
|
114 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::ConstructRequestL() - Constructed: %d" ), iConstructed ); |
|
115 #endif |
|
116 if( !iConstructed ) |
|
117 { |
|
118 RStringF method = ConstructMethodStringL(); |
|
119 CleanupClosePushL( method ); |
|
120 iHttpTransaction = iHttpSession.OpenTransactionL( iRequestUri, *iHttpResponse, method ); |
|
121 CleanupStack::PopAndDestroy(); //method |
|
122 RHTTPHeaders hdrs = iHttpTransaction.Request().GetHeaderCollection(); |
|
123 iConstructed = ETrue; |
|
124 } |
|
125 } |
|
126 |
|
127 // ---------------------------------------------------------- |
|
128 // CXcapHttpRequest::UpdateRequestUriL |
|
129 // |
|
130 // ---------------------------------------------------------- |
|
131 // |
|
132 EXPORT_C void CXcapHttpRequest::UpdateRequestUriL( const TDesC8& aUpdatedUri ) |
|
133 { |
|
134 HBufC* temp = HBufC::NewLC( aUpdatedUri.Length() ); |
|
135 temp->Des().Copy( aUpdatedUri ); |
|
136 SetRequestUriL( temp->Des() ); |
|
137 CleanupStack::PopAndDestroy(); |
|
138 } |
|
139 |
|
140 // ---------------------------------------------------------- |
|
141 // CXcapHttpRequest::ResetUriL |
|
142 // |
|
143 // ---------------------------------------------------------- |
|
144 // |
|
145 EXPORT_C void CXcapHttpRequest::ResetUriL( const TDesC& aNewUri ) |
|
146 { |
|
147 #ifdef _DEBUG |
|
148 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::ResetUriL()" ) ); |
|
149 #endif |
|
150 delete iRequestUriBuf; |
|
151 iRequestUriBuf = NULL; |
|
152 delete iWholeUri; |
|
153 iWholeUri = NULL; |
|
154 iWholeUri = HBufC8::NewL( aNewUri.Length() ); |
|
155 iWholeUri->Des().Copy( aNewUri ); |
|
156 iRequestUri.Parse( iWholeUri->Des() ); |
|
157 #ifdef _DEBUG |
|
158 TPtrC8 address( iRequestUri.UriDes() ); |
|
159 iTransportMain.WriteToLog( _L8( " New URI %S"), &address ); |
|
160 #endif |
|
161 } |
|
162 |
|
163 // ---------------------------------------------------------- |
|
164 // CXcapHttpRequest::RequestUriL |
|
165 // |
|
166 // ---------------------------------------------------------- |
|
167 // |
|
168 EXPORT_C TPtrC8 CXcapHttpRequest::RequestUriL() const |
|
169 { |
|
170 return iRequestUriBuf != NULL ? iRequestUriBuf->Des() : TPtrC8(); |
|
171 } |
|
172 |
|
173 // ---------------------------------------------------------- |
|
174 // CXcapHttpRequest::ResendL |
|
175 // |
|
176 // ---------------------------------------------------------- |
|
177 // |
|
178 CXcapHttpAuthManager& CXcapHttpRequest::AuthManager() |
|
179 { |
|
180 return iAuthManager; |
|
181 } |
|
182 |
|
183 // ---------------------------------------------------------- |
|
184 // CXcapHttpRequest::ResendWithAuthL |
|
185 // |
|
186 // ---------------------------------------------------------- |
|
187 // |
|
188 void CXcapHttpRequest::ResendWithAuthL( TInt aAuthType ) |
|
189 { |
|
190 #ifdef _DEBUG |
|
191 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::ResendWithAuthL() - Auth type: %d" ), aAuthType ); |
|
192 #endif |
|
193 iHttpTransaction.Cancel(); |
|
194 if( iExpiryTimer != NULL && iExpiryTimer->IsActive() ) |
|
195 iExpiryTimer->Cancel(); |
|
196 RHTTPHeaders hdrs = iHttpTransaction.Request().GetHeaderCollection(); |
|
197 AppendAuthorizationHeaderL( hdrs, aAuthType ); |
|
198 iHttpTransaction.SubmitL(); |
|
199 SetStatus( ETrue ); |
|
200 iActive = ETrue; |
|
201 } |
|
202 |
|
203 // ---------------------------------------------------------- |
|
204 // CXcapHttpRequest::Transaction |
|
205 // |
|
206 // ---------------------------------------------------------- |
|
207 // |
|
208 RHTTPTransaction& CXcapHttpRequest::Transaction() |
|
209 { |
|
210 return iHttpTransaction; |
|
211 } |
|
212 |
|
213 // ---------------------------------------------------------- |
|
214 // CXcapHttpRequest::RelativeUri |
|
215 // |
|
216 // ---------------------------------------------------------- |
|
217 // |
|
218 TPtrC8 CXcapHttpRequest::RelativeUri() const |
|
219 { |
|
220 TPtrC8 absolute( iRequestUri.UriDes() ); |
|
221 TPtrC8 temp( absolute.Mid( absolute.FindF( _L8( "//" ) ) + 2 ) ); |
|
222 return temp.Mid( temp.LocateF( '/' ) ); |
|
223 } |
|
224 |
|
225 // ---------------------------------------------------------- |
|
226 // CXcapHttpRequest::SetStatus |
|
227 // |
|
228 // ---------------------------------------------------------- |
|
229 // |
|
230 void CXcapHttpRequest::SetRequestUriL( const TDesC& aRequestUri ) |
|
231 { |
|
232 #ifdef _DEBUG |
|
233 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::SetRequestUriL()") ); |
|
234 #endif |
|
235 delete iRequestUriBuf; |
|
236 iRequestUriBuf = NULL; |
|
237 iRequestUriBuf = HBufC8::NewL( aRequestUri.Length() ); |
|
238 iRequestUriBuf->Des().Copy( aRequestUri ); |
|
239 TPtrC8 document = iRequestUriBuf->Des(); |
|
240 TPtrC8 root = iTransportMain.RootUri(); |
|
241 delete iWholeUri; |
|
242 iWholeUri = NULL; |
|
243 iWholeUri = HBufC8::NewL( root.Length() + document.Length() ); |
|
244 iWholeUri->Des().Copy( root ); |
|
245 iWholeUri->Des().Append( document ); |
|
246 iRequestUri.Parse( iWholeUri->Des() ); |
|
247 #ifdef _DEBUG |
|
248 TPtrC8 address( iRequestUri.UriDes() ); |
|
249 iTransportMain.WriteToLog( _L8( " URI %S"), &address ); |
|
250 #endif |
|
251 } |
|
252 |
|
253 // ---------------------------------------------------------- |
|
254 // CXcapHttpRequest::SetStatus |
|
255 // |
|
256 // ---------------------------------------------------------- |
|
257 // |
|
258 void CXcapHttpRequest::SetStatus( const TBool aSent ) |
|
259 { |
|
260 #ifdef _DEBUG |
|
261 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::SetStatus()" ) ); |
|
262 #endif |
|
263 iSent = aSent; |
|
264 if( iSent ) |
|
265 { |
|
266 if( iExpiryTimer != NULL && !iExpiryTimer->IsActive() ) |
|
267 iExpiryTimer->ActivateTimer( iExpiryTime ); |
|
268 } |
|
269 #ifdef _DEBUG |
|
270 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::SetStatus(): Status %d"), iSent ); |
|
271 #endif |
|
272 } |
|
273 |
|
274 // ---------------------------------------------------------- |
|
275 // CXcapHttpRequest::SetHeaderL |
|
276 // |
|
277 // ---------------------------------------------------------- |
|
278 // |
|
279 EXPORT_C void CXcapHttpRequest::SetHeaderL( const TDesC8& aHeaderName, |
|
280 const TDesC8& aHeaderValue ) |
|
281 { |
|
282 #ifdef _DEBUG |
|
283 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::SetHeaderL()" ) ); |
|
284 iTransportMain.WriteToLog( _L8( " Header name: %S" ), &aHeaderName ); |
|
285 iTransportMain.WriteToLog( _L8( " Header value: %S" ), &aHeaderValue ); |
|
286 #endif |
|
287 CXcapHttpHeaderModel* model = CXcapHttpHeaderModel::NewL( aHeaderName, aHeaderValue, iTransportMain ); |
|
288 CleanupStack::PushL( model ); |
|
289 User::LeaveIfError( iHeaderCollection.Append( model ) ); |
|
290 CleanupStack::Pop(); //model |
|
291 } |
|
292 |
|
293 // ---------------------------------------------------------- |
|
294 // CXcapHttpRequest::HeaderValue |
|
295 // |
|
296 // ---------------------------------------------------------- |
|
297 // |
|
298 EXPORT_C TPtrC8 CXcapHttpRequest::HeaderValue( const HTTP::TStrings aHeaderName ) const |
|
299 { |
|
300 THTTPHdrVal value; |
|
301 RStringPool stringPool = iHttpSession.StringPool(); |
|
302 RHTTPHeaders headerCollection = iHttpTransaction.Response().GetHeaderCollection(); |
|
303 RStringF hdrName = stringPool.StringF( aHeaderName, RHTTPSession::GetTable() ); |
|
304 headerCollection.GetField( hdrName, 0, value ); |
|
305 hdrName.Close(); |
|
306 if( value.Type() == THTTPHdrVal::KStrVal ) |
|
307 return value.Str().DesC(); |
|
308 else if( value.Type() == THTTPHdrVal::KStrFVal ) |
|
309 return value.StrF().DesC(); |
|
310 else return TPtrC8(); |
|
311 } |
|
312 |
|
313 // ---------------------------------------------------------- |
|
314 // CXcapHttpRequest::DoSetHeadersL |
|
315 // |
|
316 // ---------------------------------------------------------- |
|
317 // |
|
318 void CXcapHttpRequest::DoSetHeadersL() |
|
319 { |
|
320 #ifdef _DEBUG |
|
321 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::DoSetHeadersL()" ) ); |
|
322 #endif |
|
323 TInt count = iHeaderCollection.Count(); |
|
324 RHTTPHeaders hdrs = iHttpTransaction.Request().GetHeaderCollection(); |
|
325 if( iAuthManager.IsAuthorized() ) |
|
326 AppendAuthorizationHeaderL( hdrs, KAuthTypeNormal ); |
|
327 if( iConstructed && count > 0 ) |
|
328 { |
|
329 #ifdef _DEBUG |
|
330 iTransportMain.WriteToLog( _L8( "--------------------" ) ); |
|
331 iTransportMain.WriteToLog( _L8( "User-set headers:" ) ); |
|
332 #endif |
|
333 for( TInt i = 0;i < count;i++ ) |
|
334 { |
|
335 TPtrC8 name = iHeaderCollection[i]->HeaderName(); |
|
336 TPtrC8 value = iHeaderCollection[i]->HeaderValue(); |
|
337 RStringF nameString = iHttpSession.StringPool().OpenFStringL( name ); |
|
338 CleanupClosePushL( nameString ); |
|
339 RStringF valueString = iHttpSession.StringPool().OpenFStringL( value ); |
|
340 CleanupClosePushL( valueString ); |
|
341 hdrs.SetFieldL( nameString, valueString ); |
|
342 #ifdef _DEBUG |
|
343 iTransportMain.WriteToLog( _L8( "* %S: %S" ), &name, &value ); |
|
344 #endif |
|
345 CleanupStack::PopAndDestroy( 2 ); //valueString, nameString |
|
346 } |
|
347 #ifdef _DEBUG |
|
348 iTransportMain.WriteToLog( _L8( "--------------------" ) ); |
|
349 #endif |
|
350 } |
|
351 } |
|
352 |
|
353 // ---------------------------------------------------------- |
|
354 // CXcapHttpRequest::AppendAuthorizationHeaderL |
|
355 // |
|
356 // ---------------------------------------------------------- |
|
357 // |
|
358 void CXcapHttpRequest::AppendAuthorizationHeaderL( RHTTPHeaders& aHeaderCollection, TInt aAuthType ) |
|
359 { |
|
360 #ifdef _DEBUG |
|
361 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::AppendAuthorizationHeaderL()" ) ); |
|
362 #endif |
|
363 HBufC8* authorization = iAuthManager.AuthorizationL( *this ); |
|
364 if( authorization != NULL ) |
|
365 { |
|
366 RemoveDuplicateAuth(); |
|
367 CleanupStack::PushL( authorization ); |
|
368 RStringF valStr = iHttpSession.StringPool().OpenFStringL( *authorization ); |
|
369 CleanupClosePushL( valStr ); |
|
370 switch( aAuthType ) |
|
371 { |
|
372 case KAuthTypeNormal: |
|
373 aHeaderCollection.SetFieldL( iHttpSession.StringPool().StringF( |
|
374 HTTP::EAuthorization, RHTTPSession::GetTable() ), valStr ); |
|
375 break; |
|
376 case KAuthTypeProxy: |
|
377 aHeaderCollection.SetFieldL( iHttpSession.StringPool().StringF( |
|
378 HTTP::EProxyAuthorization, RHTTPSession::GetTable() ), valStr ); |
|
379 break; |
|
380 default: |
|
381 #ifdef _DEBUG |
|
382 iTransportMain.WriteToLog( _L8( " Default case: %d" ), aAuthType ); |
|
383 #endif |
|
384 break; |
|
385 } |
|
386 CleanupStack::PopAndDestroy( 2 ); //valStr, authorization |
|
387 } |
|
388 } |
|
389 |
|
390 // ---------------------------------------------------------- |
|
391 // CXcapHttpRequest::RemoveDuplicateAuth |
|
392 // |
|
393 // ---------------------------------------------------------- |
|
394 // |
|
395 void CXcapHttpRequest::RemoveDuplicateAuth() |
|
396 { |
|
397 #ifdef _DEBUG |
|
398 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::RemoveDuplicateAuth()" ) ); |
|
399 #endif |
|
400 RStringPool spool = iHttpSession.StringPool(); |
|
401 RHTTPHeaders requestHeaders( iHttpTransaction.Request().GetHeaderCollection() ); |
|
402 //Check for existence of the header is not needed, remove both if they're there |
|
403 requestHeaders.RemoveField( spool.StringF( HTTP::EAuthorization, RHTTPSession::GetTable() ) ); |
|
404 requestHeaders.RemoveField( spool.StringF( HTTP::EProxyAuthorization, RHTTPSession::GetTable() ) ); |
|
405 } |
|
406 |
|
407 // ---------------------------------------------------------- |
|
408 // CXcapHttpRequest::AppendDataL |
|
409 // |
|
410 // ---------------------------------------------------------- |
|
411 // |
|
412 void CXcapHttpRequest::AppendDataL( const TPtrC8& aBodyPart ) |
|
413 { |
|
414 #ifdef _DEBUG |
|
415 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::AppendDataL() - Current: %d" ), |
|
416 iCurrentDataLength ); |
|
417 #endif |
|
418 iResponseBuffer->ResizeL( iCurrentDataLength + aBodyPart.Length() ); |
|
419 iResponseBuffer->Write( iCurrentDataLength, aBodyPart ); |
|
420 iCurrentDataLength = iCurrentDataLength + aBodyPart.Length(); |
|
421 #ifdef _DEBUG |
|
422 iTransportMain.WriteToLog( _L8( " Current: %d" ), iCurrentDataLength ); |
|
423 iTransportMain.WriteToLog( _L8( " Buffer size: %d" ), iResponseBuffer->Size() ); |
|
424 #endif |
|
425 } |
|
426 |
|
427 // ---------------------------------------------------------- |
|
428 // CXcapHttpRequest::SetStatus |
|
429 // |
|
430 // ---------------------------------------------------------- |
|
431 // |
|
432 RHTTPSession& CXcapHttpRequest::Session() |
|
433 { |
|
434 return iHttpSession; |
|
435 } |
|
436 |
|
437 // ---------------------------------------------------------- |
|
438 // CXcapHttpRequest::SetStatus |
|
439 // |
|
440 // ---------------------------------------------------------- |
|
441 // |
|
442 EXPORT_C TXdmCompletionData* CXcapHttpRequest::ResponseData() |
|
443 { |
|
444 return &iRespData; |
|
445 } |
|
446 |
|
447 // ---------------------------------------------------------- |
|
448 // CXcapHttpRequest::ReleaseResponseData |
|
449 // |
|
450 // ---------------------------------------------------------- |
|
451 // |
|
452 EXPORT_C void CXcapHttpRequest::ReleaseResponseData() |
|
453 { |
|
454 #ifdef _DEBUG |
|
455 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::ReleaseResponseData()" ) ); |
|
456 #endif |
|
457 if( iRespData.iETag != NULL ) |
|
458 { |
|
459 delete iRespData.iETag; |
|
460 iRespData.iETag = NULL; |
|
461 } |
|
462 if( iRespData.iStatusText != NULL ) |
|
463 { |
|
464 delete iRespData.iStatusText; |
|
465 iRespData.iStatusText = NULL; |
|
466 } |
|
467 if( iRespData.iResponseData != NULL ) |
|
468 { |
|
469 delete iRespData.iResponseData; |
|
470 iRespData.iResponseData = NULL; |
|
471 } |
|
472 if( iConstructed ) |
|
473 { |
|
474 iConstructed = EFalse; |
|
475 iHttpTransaction.Close(); |
|
476 } |
|
477 iHeaderCollection.ResetAndDestroy(); |
|
478 } |
|
479 |
|
480 // ---------------------------------------------------------- |
|
481 // CXcapHttpRequest::SetExpiryTimeL |
|
482 // |
|
483 // ---------------------------------------------------------- |
|
484 // |
|
485 EXPORT_C void CXcapHttpRequest::SetExpiryTimeL( MXcapHttpRequestTimerCallback* /*aCallback*/, |
|
486 const TTimeIntervalMicroSeconds32 aExpiryTime ) |
|
487 { |
|
488 #ifdef _DEBUG |
|
489 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::SetExpiryTimeL()" ) ); |
|
490 #endif |
|
491 if( iExpiryTimer == NULL ) |
|
492 iExpiryTimer = CXcapHttpRequestTimer::NewL( iTransportMain, this ); |
|
493 iExpiryTime = aExpiryTime; |
|
494 } |
|
495 |
|
496 // ---------------------------------------------------------- |
|
497 // CXcapHttpRequest::FinaliseRequestL |
|
498 // |
|
499 // ---------------------------------------------------------- |
|
500 // |
|
501 void CXcapHttpRequest::FinaliseRequestL( TInt aErrorCode ) |
|
502 { |
|
503 #ifdef _DEBUG |
|
504 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::FinaliseRequestL()" ) ); |
|
505 iTransportMain.WriteToLog( _L8( " Error: %d" ), aErrorCode ); |
|
506 iTransportMain.WriteToLog( _L8( " Active: %d" ), iActive ); |
|
507 #endif |
|
508 if( iActive ) |
|
509 { |
|
510 iActive = EFalse; |
|
511 if( iExpiryTimer ) |
|
512 iExpiryTimer->Cancel(); |
|
513 PrepareResponseBodyL(); |
|
514 CompileResponseDataL( aErrorCode ); |
|
515 User::RequestComplete( iClientStatus, aErrorCode ); |
|
516 delete iWholeUri; |
|
517 iWholeUri = NULL; |
|
518 } |
|
519 } |
|
520 |
|
521 // ---------------------------------------------------------- |
|
522 // CXcapHttpRequest::CancelRequest |
|
523 // |
|
524 // ---------------------------------------------------------- |
|
525 // |
|
526 EXPORT_C void CXcapHttpRequest::CancelRequest() |
|
527 { |
|
528 #ifdef _DEBUG |
|
529 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::CancelRequest()" ) ); |
|
530 #endif |
|
531 if( iActive ) |
|
532 { |
|
533 #ifdef _DEBUG |
|
534 iTransportMain.WriteToLog( _L8( " Request is active, cancelling..." ) ); |
|
535 #endif |
|
536 if( iExpiryTimer ) |
|
537 iExpiryTimer->Cancel(); |
|
538 iActive = EFalse; |
|
539 iConstructed = EFalse; |
|
540 iHttpTransaction.Close(); |
|
541 iRespData.iETag = NULL; |
|
542 iRespData.iStatusText = NULL; |
|
543 iRespData.iResponseData = NULL; |
|
544 iRespData.iCompletion = KErrCancel; |
|
545 iRespData.iHttpStatus = KErrCancel; |
|
546 User::RequestComplete( iClientStatus, KErrCancel ); |
|
547 #ifdef _DEBUG |
|
548 iTransportMain.WriteToLog( _L8( " Request completed with KErrCancel" ) ); |
|
549 #endif |
|
550 } |
|
551 } |
|
552 |
|
553 // ---------------------------------------------------------- |
|
554 // CXcapHttpRequest::CompileResponseData |
|
555 // |
|
556 // ---------------------------------------------------------- |
|
557 // |
|
558 void CXcapHttpRequest::CompileResponseDataL( TInt aErrorCode ) |
|
559 { |
|
560 #ifdef _DEBUG |
|
561 iTransportMain.WriteToLog( _L( "CXcapHttpRequest::CompileResponseData()" ) ); |
|
562 #endif |
|
563 RHTTPResponse response = iHttpTransaction.Response(); |
|
564 TInt statusInt = response.StatusCode(); |
|
565 RStringF statusStr = response.StatusText(); |
|
566 HBufC8* statusBuf = statusStr.DesC().AllocLC(); |
|
567 TPtrC8 etagDesc( HeaderValue( HTTP::EETag ) ); |
|
568 HBufC8* eTag = etagDesc.Length() > 0 ? etagDesc.AllocL() : NULL; |
|
569 iRespData.iETag = eTag; |
|
570 iRespData.iHttpStatus = statusInt; |
|
571 iRespData.iStatusText = statusBuf; |
|
572 iRespData.iCompletion = aErrorCode; |
|
573 iRespData.iResponseData = iFlatResponse; |
|
574 CleanupStack::Pop(); //statusBuf |
|
575 #ifdef _DEBUG |
|
576 if( iRespData.iResponseData != NULL ) |
|
577 { |
|
578 TBuf<32> response( _L( "response" ) ); |
|
579 response.AppendNum( iHttpTransaction.Id() ); |
|
580 response.Append( _L( ".xml" ) ); |
|
581 DumpResponseL( *iRespData.iResponseData, response ); |
|
582 } |
|
583 #endif |
|
584 } |
|
585 |
|
586 #ifdef _DEBUG |
|
587 // --------------------------------------------------------- |
|
588 // CXcapHttpRequest::DumpResponseL |
|
589 // |
|
590 // --------------------------------------------------------- |
|
591 // |
|
592 void CXcapHttpRequest::DumpResponseL( const TDesC8& aRespData, const TDesC& aDumpName ) |
|
593 { |
|
594 RFile file; |
|
595 RFs session; |
|
596 TBuf<512> path( _L( "C:\\logs\\XDM\\" ) ); |
|
597 path.Append( aDumpName ); |
|
598 User::LeaveIfError( session.Connect() ); |
|
599 TInt error( file.Replace( session, path, EFileWrite ) ); |
|
600 if( error == KErrNone ) |
|
601 { |
|
602 file.Write( aRespData ); |
|
603 file.Close(); |
|
604 } |
|
605 session.Close(); |
|
606 } |
|
607 #endif |
|
608 |
|
609 // ---------------------------------------------------------- |
|
610 // CXcapHttpRequest::PrepareResponseBodyL |
|
611 // |
|
612 // ---------------------------------------------------------- |
|
613 // |
|
614 void CXcapHttpRequest::PrepareResponseBodyL() |
|
615 { |
|
616 #ifdef _DEBUG |
|
617 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::PrepareResponseBodyL()" ) ); |
|
618 #endif |
|
619 iResponseBuffer->Compress(); |
|
620 TInt dataLength = iResponseBuffer->Size(); |
|
621 #ifdef _DEBUG |
|
622 TInt contentLength = iHttpResponse->ContentLengthL(); |
|
623 if( contentLength >= 0 && contentLength < KMaxTInt ) |
|
624 { |
|
625 TPtrC8 result; |
|
626 contentLength == dataLength ? result.Set( _L8( "Correct" ) ) : |
|
627 result.Set( _L8( "Values do not match!" ) ); |
|
628 iTransportMain.WriteToLog( _L8( " Actual length: %d *** Content-Length: %d => %S" ), |
|
629 dataLength, contentLength, &result ); |
|
630 } |
|
631 #endif |
|
632 if( dataLength > 0 ) |
|
633 { |
|
634 iFlatResponse = HBufC8::NewL( dataLength ); |
|
635 TPtr8 pointer( iFlatResponse->Des() ); |
|
636 iResponseBuffer->Read( 0, pointer, dataLength ); |
|
637 //pointer.Copy( iResponseBuffer->Ptr( 0 ) ); |
|
638 iResponseBuffer->Reset(); |
|
639 iCurrentDataLength = 0; |
|
640 } |
|
641 } |
|
642 |
|
643 // ---------------------------------------------------------- |
|
644 // CXcapHttpRequest::HandleTimerEventL |
|
645 // |
|
646 // ---------------------------------------------------------- |
|
647 // |
|
648 void CXcapHttpRequest::HandleTimerEventL() |
|
649 { |
|
650 #ifdef _DEBUG |
|
651 iTransportMain.WriteToLog( _L8( "CXcapHttpRequest::HandleTimerEventL()" ) ); |
|
652 #endif |
|
653 iHttpTransaction.Close(); |
|
654 iActive = EFalse; |
|
655 iConstructed = EFalse; |
|
656 iRespData.iETag = NULL; |
|
657 iRespData.iStatusText = NULL; |
|
658 iRespData.iResponseData = NULL; |
|
659 iRespData.iCompletion = KErrTimedOut; |
|
660 iRespData.iHttpStatus = KErrTimedOut; |
|
661 User::RequestComplete( iClientStatus, KErrTimedOut ); |
|
662 #ifdef _DEBUG |
|
663 iTransportMain.WriteToLog( _L8( " Request completed with KErrTimedOut" ) ); |
|
664 #endif |
|
665 } |
|
666 |
|
667 // --------------------------------------------------------- |
|
668 // CXcapHttpRequest::TimeL |
|
669 // |
|
670 // --------------------------------------------------------- |
|
671 // |
|
672 TInt CXcapHttpRequest::TimeL() const |
|
673 { |
|
674 TInt period = 0; |
|
675 User::LeaveIfError( HAL::Get( HALData::ESystemTickPeriod, period ) ); |
|
676 TInt millisecsPerTick = period / 1000; |
|
677 return User::TickCount() * millisecsPerTick; |
|
678 } |
|
679 |
|
680 // End of file |
|
681 |