|
1 // Copyright (c) 2002-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // $Header$ |
|
15 // by: |
|
16 // for: |
|
17 // Include Files |
|
18 // |
|
19 // |
|
20 |
|
21 #include <e32base.h> |
|
22 #include "CHTTPFamily.h" |
|
23 #include "httptransaction.h" |
|
24 |
|
25 // panic msg |
|
26 _LIT(KBufferPanic, "HTTPTRANSACTION-BUFFER"); |
|
27 const TInt KMaxFileBufferSize = 65535; |
|
28 |
|
29 //_LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S.%C%:3"); |
|
30 _LIT(KDateFormat,"%D%M%Y%/0%1%/1%2%/2%3%/3 %:0%H%:1%T%:2%S"); |
|
31 |
|
32 _LIT(KITHContentType, "ContentType"); // Integration Test Harness $$ var name |
|
33 _LIT(KHTTPContentType, "Content-Type"); // HTTP Protocol |
|
34 |
|
35 _LIT(KITHContentLength, "ContentLength"); // Integration Test Harness $$ var name |
|
36 |
|
37 _LIT(KITHAccept, "Accept"); // Integration Test Harness $$ var name |
|
38 |
|
39 _LIT(KITHAcceptCharSet, "AcceptCharSet"); // Integration Test Harness $$ var name |
|
40 |
|
41 _LIT(KITHUserAgent, "UserAgent"); // Integration Test Harness $$ var name |
|
42 |
|
43 _LIT(KITHAcceptEncoding, "AcceptEncoding"); // Integration Test Harness $$ var name |
|
44 |
|
45 |
|
46 _LIT(KITHDisablePipelining, "DisablePipelining"); |
|
47 _LIT(KITHYes,"Y"); |
|
48 |
|
49 const TInt K_OUTOFBOUNDS_YEAR = 2499; |
|
50 |
|
51 void CTestTransaction::Log(TRefByValue<const TDesC> aFmt, ... ) |
|
52 { |
|
53 VA_LIST list; |
|
54 VA_START(list, aFmt); |
|
55 |
|
56 Machine()->MsgPrintfln(aFmt, list); |
|
57 } |
|
58 |
|
59 void CTestTransaction::WriteDateStamp() |
|
60 { |
|
61 TDateTime myTempDate(K_OUTOFBOUNDS_YEAR, EJanuary, 0,0,0,0,0); |
|
62 WriteDateStamp(myTempDate); |
|
63 } |
|
64 |
|
65 void CTestTransaction::WriteDateStamp(const TDateTime &aDate) |
|
66 { |
|
67 TDateTime date; |
|
68 TTime now; |
|
69 TBool iEOL = (aDate.Year() == K_OUTOFBOUNDS_YEAR); |
|
70 |
|
71 if (iEOL) |
|
72 { |
|
73 now.HomeTime(); |
|
74 date = now.DateTime(); |
|
75 } |
|
76 else |
|
77 date = aDate; |
|
78 |
|
79 TTime t(date); |
|
80 TBuf<128> dateTimeString; |
|
81 TRAPD(err, t.FormatL(dateTimeString, KDateFormat)); |
|
82 if (err == KErrNone) |
|
83 { |
|
84 if (iEOL) |
|
85 Machine()->MsgPrintf(_L("[%S] "), &dateTimeString); |
|
86 else |
|
87 Log(_L("[%S]\r\n"), &dateTimeString); |
|
88 } |
|
89 } |
|
90 |
|
91 TInt CTestTransaction::Error( TInt aError, TRefByValue<const TDesC> aFmt, ... ) |
|
92 { |
|
93 VA_LIST list; |
|
94 VA_START(list, aFmt); |
|
95 Machine()->MsgPrintfln(aFmt, list); |
|
96 return aError; |
|
97 } |
|
98 |
|
99 CTestTransaction *CTestTransaction::NewL( RHTTPSession& aSession, |
|
100 HTTP::TStrings aTransactiontype, |
|
101 const TDesC& aUri, |
|
102 const TDesC &aFilename, |
|
103 const TDesC &aTransactionName, |
|
104 CTEngine *aTestMachine) |
|
105 { |
|
106 CTestTransaction *self = NewLC( aSession, |
|
107 aTransactiontype, |
|
108 aUri, |
|
109 aFilename, |
|
110 aTransactionName, |
|
111 aTestMachine); |
|
112 CleanupStack::Pop(); |
|
113 return self; |
|
114 } |
|
115 |
|
116 //----------------------------------------------------------------------------- |
|
117 |
|
118 CTestTransaction *CTestTransaction::NewLC( RHTTPSession& aSession, |
|
119 HTTP::TStrings aTransactiontype, |
|
120 const TDesC& aUri, |
|
121 const TDesC &aFilename, |
|
122 const TDesC &aTransactionName, |
|
123 CTEngine *aTestMachine) |
|
124 { |
|
125 CTestTransaction* self = new (ELeave) CTestTransaction( aTransactiontype, |
|
126 aUri, |
|
127 aFilename, |
|
128 aTransactionName, |
|
129 aTestMachine); |
|
130 |
|
131 |
|
132 CleanupStack::PushL(self); |
|
133 self->ConstructL(aSession); |
|
134 return self; |
|
135 } |
|
136 |
|
137 //----------------------------------------------------------------------------- |
|
138 |
|
139 void CTestTransaction::ConstructL(RHTTPSession& aSession) |
|
140 { |
|
141 TBool hasRequestBody = EFalse; |
|
142 |
|
143 switch (iTransactionType) |
|
144 { |
|
145 case HTTP::EPOST : |
|
146 case HTTP::EPUT : |
|
147 |
|
148 if (iFilename.Length() > 0) |
|
149 { |
|
150 User::LeaveIfError(SetFileNameL(iFilename)); |
|
151 |
|
152 hasRequestBody = ETrue; |
|
153 } |
|
154 break ; |
|
155 |
|
156 case HTTP::EGET : |
|
157 case HTTP::EDELETE: |
|
158 case HTTP::EHEAD: |
|
159 case HTTP::ECONNECT : |
|
160 default: |
|
161 ; |
|
162 } |
|
163 |
|
164 TUriParser8 KURI; |
|
165 KURI.Parse(iUri); |
|
166 |
|
167 RStringPool strPool = aSession.StringPool(); |
|
168 |
|
169 // open a transaction within the required session and use the class callback object for |
|
170 // managing the subsequent events... |
|
171 |
|
172 iTransaction = aSession.OpenTransactionL(KURI, *this, strPool.StringF(iTransactionType, RHTTPSession::GetTable())); |
|
173 |
|
174 iState = EActive; |
|
175 |
|
176 RHTTPRequest request = iTransaction.Request(); |
|
177 |
|
178 RHTTPHeaders headers = request.GetHeaderCollection(); |
|
179 |
|
180 AddAcceptHeaderL(headers, strPool); |
|
181 |
|
182 SetUserAgentL(headers, strPool); |
|
183 |
|
184 SetContentLengthL(headers, strPool); |
|
185 |
|
186 AcceptEncodingL(headers, strPool); |
|
187 |
|
188 // Check to see if pipelining should be disabled |
|
189 |
|
190 if (Machine()->GetDefine(KITHDisablePipelining).CompareF(KITHYes)==0) |
|
191 { |
|
192 RHTTPTransactionPropertySet transactionPropertySet = iTransaction.PropertySet(); |
|
193 RStringF name = strPool.StringF(HTTP::EHttpPipelining, RHTTPSession::GetTable()); |
|
194 RStringF value = strPool.StringF(HTTP::EDisablePipelining,RHTTPSession::GetTable()); |
|
195 transactionPropertySet.SetPropertyL(name,value); |
|
196 } |
|
197 |
|
198 |
|
199 |
|
200 // Add request body |
|
201 if (hasRequestBody) |
|
202 { |
|
203 if (!AddRequestBodyL(headers, strPool)) |
|
204 User::LeaveIfError(KErrArgument); |
|
205 } |
|
206 } |
|
207 |
|
208 //----------------------------------------------------------------------------- |
|
209 |
|
210 CTestTransaction::CTestTransaction( HTTP::TStrings aTransactionType, |
|
211 const TDesC& aUri, |
|
212 const TDesC &aFilename, |
|
213 const TDesC &aTransactionName, |
|
214 CTEngine *aTestMachine): iFileBufferPtr(0,0) |
|
215 { |
|
216 iTransactionType = aTransactionType; |
|
217 iUri.Copy(aUri); |
|
218 iFilename.Copy(aFilename); |
|
219 iTransactionName.Copy(aTransactionName); |
|
220 iEngine = aTestMachine ; |
|
221 iState = EUnInitialised; |
|
222 } |
|
223 |
|
224 CTestTransaction::~CTestTransaction(void) |
|
225 { |
|
226 Machine()->DeleteErrorDefine(iTransactionName); |
|
227 Machine()->DeleteResultDefine(iTransactionName); |
|
228 } |
|
229 |
|
230 |
|
231 TBool CTestTransaction::GetNextDataPart(TPtrC8 &aDataPart) |
|
232 { |
|
233 // __ASSERT_DEBUG(iFileBuffer, User::Panic(KBufferPanic, EBufferNotAllocated)); |
|
234 Log(_L("GetNextDataPart")); |
|
235 // Read from the request body file |
|
236 TBool retVal = EFalse; |
|
237 if ( (iFileBuffer->Des().Length() == 0) && ( (iDataChunkCount == 0) || iReleaseData) ) |
|
238 { |
|
239 TInt err = iReqFile.Read(iFileBufferPtr); |
|
240 if (err == KErrNone) |
|
241 { |
|
242 aDataPart.Set(iFileBufferPtr); |
|
243 if (iFileBufferPtr.Length() == 0) |
|
244 { |
|
245 iReqFile.Close(); |
|
246 retVal = ETrue; |
|
247 } |
|
248 } |
|
249 } |
|
250 else |
|
251 { |
|
252 aDataPart.Set(iFileBufferPtr); |
|
253 if (iFileBufferPtr.Length() == 0) |
|
254 retVal = ETrue; |
|
255 } |
|
256 |
|
257 iReleaseData = EFalse; |
|
258 return retVal; |
|
259 } |
|
260 |
|
261 TInt CTestTransaction::OverallDataSize() |
|
262 { |
|
263 Log(_L("OverallDataSize")); |
|
264 TInt size = 0; |
|
265 if (iReqFile.Size(size)) |
|
266 User::Panic(KBufferPanic, EInvalidFileSizeError); |
|
267 |
|
268 return size; |
|
269 } |
|
270 |
|
271 //----------------------------------------------------------------------------- |
|
272 // Clear out the submit buffer |
|
273 |
|
274 void CTestTransaction::ReleaseData() |
|
275 { |
|
276 Log(_L("ReleaseData")); |
|
277 iReleaseData = ETrue; |
|
278 ++iDataChunkCount; |
|
279 if (iFileBuffer->Des().Length() != 0) |
|
280 { |
|
281 TRAPD(error, iTransaction.NotifyNewRequestBodyPartL()); |
|
282 if (error != KErrNone) |
|
283 { |
|
284 Log(_L("RHTTPTransaction::NotifyNewRequestBodyPartL %d"), error); |
|
285 } |
|
286 iFileBuffer->Des().Zero(); |
|
287 } |
|
288 } |
|
289 |
|
290 //----------------------------------------------------------------------------- |
|
291 |
|
292 TInt CTestTransaction::Reset() |
|
293 { |
|
294 return KErrNotSupported; |
|
295 } |
|
296 |
|
297 void CTestTransaction::DoneWaitEvents() |
|
298 { |
|
299 // complete the test machine - whll then get the next command |
|
300 Machine()->CompleteRequest(); |
|
301 } |
|
302 |
|
303 //----------------------------------------------------------------------------- |
|
304 void CTestTransaction::SetTransaction(RHTTPTransaction &aTransaction) |
|
305 { |
|
306 iTransaction = aTransaction; |
|
307 } |
|
308 |
|
309 const RHTTPTransaction &CTestTransaction::Transaction() const |
|
310 { |
|
311 return (iTransaction); |
|
312 } |
|
313 |
|
314 TInt CTestTransaction::SetFileNameL(const TDesC &aName) |
|
315 { |
|
316 TInt err = Machine()->SetFileName(aName, iReqFile); |
|
317 |
|
318 if (err == KErrNone) |
|
319 { |
|
320 // recreate the buffer to hold the file |
|
321 delete iFileBuffer; |
|
322 iFileBuffer = NULL; // ensure we zap it completely!!! |
|
323 iFileBuffer = HBufC8::NewMaxL(KMaxFileBufferSize); |
|
324 iFileBuffer->Des().Zero(); |
|
325 iFileBufferPtr.Set(iFileBuffer->Des()); |
|
326 } |
|
327 |
|
328 return err; |
|
329 } |
|
330 |
|
331 TBool CTestTransaction::AddRequestBodyL( RHTTPHeaders &aHeaders, |
|
332 RStringPool &aStrPool) |
|
333 { |
|
334 // the content type info will be in $ContentType$. If NULL or Empty then an error generated |
|
335 TBuf8<KMaxContentTypeSize> contTypeBuf; |
|
336 contTypeBuf.Copy(Machine()->GetDefine(KITHContentType)); |
|
337 if (contTypeBuf.Length() == 0) |
|
338 return EFalse; //Error(KErrArgument, THA_KErrNoContentTypeDefined, &transmthd); |
|
339 |
|
340 RStringF contTypeStr = aStrPool.OpenFStringL(contTypeBuf); |
|
341 THTTPHdrVal contType(contTypeStr); |
|
342 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentType, RHTTPSession::GetTable()), contType); |
|
343 contTypeStr.Close(); |
|
344 |
|
345 MHTTPDataSupplier *dataSupplier = this; |
|
346 |
|
347 iTransaction.Request().SetBody(*dataSupplier); |
|
348 |
|
349 return ETrue; |
|
350 } |
|
351 |
|
352 //----------------------------------------------------------------------------- |
|
353 |
|
354 TBool CTestTransaction::AddAcceptHeaderL(RHTTPHeaders &aHeaders, RStringPool &aStrPool) |
|
355 { |
|
356 // some tests may require specific 'Accept' parameters |
|
357 TBuf8<KMaxAcceptLengthSize> acceptBuf; |
|
358 acceptBuf.Copy(Machine()->GetDefine(KITHAccept)); |
|
359 RStringF accept = (acceptBuf.Length() == 0) ? |
|
360 aStrPool.StringF(HTTP::EAnyAny, RHTTPSession::GetTable()) : aStrPool.OpenFStringL(acceptBuf); |
|
361 THTTPHdrVal acceptHdr(accept); |
|
362 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAccept, RHTTPSession::GetTable()), acceptHdr); |
|
363 accept.Close(); |
|
364 return ETrue; |
|
365 } |
|
366 |
|
367 //----------------------------------------------------------------------------- |
|
368 // some tests may require specific 'Accept' parameters |
|
369 |
|
370 TBool CTestTransaction::AcceptCharSetL(RHTTPHeaders &aHeaders, RStringPool &aStrPool) |
|
371 { |
|
372 TBuf8<KMaxAcceptCharSetSize> acceptCharSetBuf; |
|
373 acceptCharSetBuf.Copy(Machine()->GetDefine(KITHAcceptCharSet)); |
|
374 if (acceptCharSetBuf.Length() > 0) |
|
375 { |
|
376 RStringF accept = aStrPool.OpenFStringL(acceptCharSetBuf); |
|
377 THTTPHdrVal acceptCharSetHdr(accept); |
|
378 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()), acceptCharSetHdr); |
|
379 accept.Close(); |
|
380 } |
|
381 |
|
382 return ETrue; |
|
383 } |
|
384 |
|
385 void CTestTransaction::SubmitL() |
|
386 { |
|
387 iTransaction.SubmitL(); |
|
388 } |
|
389 |
|
390 TInt CTestTransaction::MHFRunError(TInt aError, |
|
391 RHTTPTransaction aTransaction, |
|
392 const THTTPEvent& aEvent) |
|
393 { |
|
394 // date stamp the response |
|
395 WriteDateStamp(); |
|
396 Log(_L("MHFRunError : Test failed with error code %d"), aError); |
|
397 |
|
398 Machine()->SetErrorDefine(iTransactionName, aEvent.iStatus); |
|
399 |
|
400 // set the response status code for processing l8r... |
|
401 TInt statusCode = aTransaction.Response().StatusCode(); |
|
402 |
|
403 // date stamp the response |
|
404 WriteDateStamp(); |
|
405 |
|
406 Log(_L("Event Status Code: %d"), statusCode); |
|
407 |
|
408 Machine()->SetResultDefine(iTransactionName, statusCode); |
|
409 |
|
410 // SetCompletionCode(statusCode); |
|
411 |
|
412 return KErrNone; |
|
413 } |
|
414 |
|
415 //----------------------------------------------------------------------------- |
|
416 // some tests may require specific 'AcceptEncoding' parameters |
|
417 |
|
418 TBool CTestTransaction::AcceptEncodingL(RHTTPHeaders &aHeaders, RStringPool &aStrPool) |
|
419 { |
|
420 TBuf8<KMaxAcceptEncodingSize> acceptEncodingBuf; |
|
421 acceptEncodingBuf.Copy(Machine()->GetDefine(KITHAcceptEncoding)); |
|
422 if (acceptEncodingBuf.Length() > 0) |
|
423 { |
|
424 RStringF acceptEncoding = aStrPool.OpenFStringL(acceptEncodingBuf); |
|
425 THTTPHdrVal acceptEncodingHdr(acceptEncoding); |
|
426 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EAcceptCharset, RHTTPSession::GetTable()), acceptEncodingHdr); |
|
427 acceptEncoding.Close(); |
|
428 } |
|
429 |
|
430 return ETrue; |
|
431 } |
|
432 |
|
433 //----------------------------------------------------------------------------- |
|
434 // Add User Agent to header if supplied else default |
|
435 |
|
436 TBool CTestTransaction::SetUserAgentL(RHTTPHeaders &aHeaders, RStringPool &aStrPool) |
|
437 { |
|
438 // get the DEFINE for UserAgent |
|
439 TBuf8<KMaxUserAgentSize> userAgentBuf; |
|
440 userAgentBuf.Copy(Machine()->GetDefine(KITHUserAgent)); |
|
441 |
|
442 TInt iLen = userAgentBuf.Length(); |
|
443 // assign the selection |
|
444 RStringF agent = (iLen == 0) ? aStrPool.OpenFStringL(KUserAgent) : aStrPool.OpenFStringL(userAgentBuf); |
|
445 THTTPHdrVal userAgent(agent); |
|
446 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EUserAgent, RHTTPSession::GetTable()), userAgent); |
|
447 agent.Close(); |
|
448 |
|
449 return ETrue; |
|
450 } |
|
451 |
|
452 //----------------------------------------------------------------------------- |
|
453 // Add Content Length Header |
|
454 |
|
455 TBool CTestTransaction::SetContentLengthL(RHTTPHeaders &aHeaders, RStringPool &aStrPool) |
|
456 { |
|
457 TBuf8<KMaxContentLengthSize> contLengthBuf; |
|
458 contLengthBuf.Copy(Machine()->GetDefine(KITHContentLength)); |
|
459 if (contLengthBuf.Length() != 0) |
|
460 { |
|
461 RStringF contLengthStr = aStrPool.OpenFStringL(contLengthBuf); |
|
462 THTTPHdrVal contLength(contLengthStr); |
|
463 aHeaders.SetFieldL(aStrPool.StringF(HTTP::EContentLength, RHTTPSession::GetTable()), contLength); |
|
464 contLengthStr.Close(); |
|
465 } |
|
466 |
|
467 return ETrue; |
|
468 } |
|
469 |
|
470 //----------------------------------------------------------------------------- |
|
471 // dump all the body's chunks |
|
472 |
|
473 void CTestTransaction::DumpResponseBody(RHTTPTransaction &aTrans) |
|
474 { |
|
475 |
|
476 MHTTPDataSupplier *body = aTrans.Response().Body(); |
|
477 TPtrC8 dataChunk; |
|
478 TBool isLast = body->GetNextDataPart(dataChunk); |
|
479 Machine()->DumpData(dataChunk); |
|
480 if (isLast)// && !iEngine->IsSilent()) |
|
481 { |
|
482 // date stamp the response |
|
483 WriteDateStamp(); |
|
484 Log(_L(" - Got last data chunk.")); |
|
485 } |
|
486 body->ReleaseData(); |
|
487 } |
|
488 |
|
489 |
|
490 void CTestTransaction::DumpRespHeaders(RHTTPTransaction &aTrans) |
|
491 { |
|
492 |
|
493 RHTTPResponse resp = aTrans.Response(); |
|
494 RStringPool strP = aTrans.Session().StringPool(); |
|
495 RHTTPHeaders hdr = resp.GetHeaderCollection(); |
|
496 THTTPHdrFieldIter it = hdr.Fields(); |
|
497 |
|
498 TBuf<32> fieldName16; |
|
499 TBuf<128> fieldVal16; |
|
500 |
|
501 while (it.AtEnd() == EFalse) |
|
502 { |
|
503 RStringTokenF fieldNameTk = it(); |
|
504 RStringF fieldName = strP.StringF(fieldNameTk); |
|
505 THTTPHdrVal hVal; |
|
506 if (hdr.GetField(fieldName, 0, hVal) == KErrNone) |
|
507 { |
|
508 TPtrC8 fieldNameStr(strP.StringF(fieldName).DesC()); |
|
509 if (fieldNameStr.Length() > 32) |
|
510 fieldNameStr.Set(fieldNameStr.Left(32)); |
|
511 |
|
512 fieldName16.Copy(fieldNameStr); |
|
513 |
|
514 THTTPHdrVal fieldVal; |
|
515 hdr.GetField(fieldName, 0, fieldVal); |
|
516 switch (fieldVal.Type()) |
|
517 { |
|
518 case THTTPHdrVal::KTIntVal: Log(_L("%S: %d"), &fieldName16, fieldVal.Int()); break; |
|
519 case THTTPHdrVal::KStrVal: |
|
520 case THTTPHdrVal::KStrFVal: |
|
521 { |
|
522 TPtrC8 fieldValStr(strP.StringF(fieldVal.StrF()).DesC()); |
|
523 if (fieldValStr.Length() > 128) |
|
524 fieldValStr.Set(fieldValStr.Left(128)); |
|
525 |
|
526 fieldVal16.Copy(fieldValStr); |
|
527 Log(_L("%S: %S"), &fieldName16, &fieldVal16); |
|
528 |
|
529 // see if we've got the Content-Type header |
|
530 if (fieldName16.Find(KHTTPContentType) != KErrNotFound) |
|
531 { |
|
532 // check that the contenttype script sets matches (in some way) received header |
|
533 TBuf8<KMaxContentTypeSize> contTypeBuf; |
|
534 contTypeBuf.Copy(Machine()->GetDefine(KITHContentType)); |
|
535 |
|
536 TInt iPos = fieldValStr.Find(contTypeBuf); |
|
537 if (iPos == KErrNotFound) |
|
538 Log(_L(" - Content Type string [%S:%S] is different to ContentType setting"), &fieldName16, &fieldVal16); |
|
539 else |
|
540 Log(_L(" - Content Type [%S:%S] acknowledged"), &fieldName16, &fieldVal16); |
|
541 } |
|
542 } |
|
543 break; |
|
544 case THTTPHdrVal::KDateVal: |
|
545 { |
|
546 TDateTime myDate = fieldVal.DateTime(); |
|
547 WriteDateStamp(myDate); |
|
548 Log(_L(" : %S"), &fieldName16); |
|
549 } |
|
550 break; |
|
551 |
|
552 default: Log(_L("%S: <unrecognised value type>"), &fieldName16); break; |
|
553 } |
|
554 } |
|
555 ++it; |
|
556 } |
|
557 } |
|
558 |
|
559 void CTestTransaction::CloseTransaction() |
|
560 { |
|
561 if (iState != EClosed) |
|
562 { |
|
563 iTransaction.Close(); |
|
564 iState = EClosed; |
|
565 } |
|
566 } |
|
567 |
|
568 void CTestTransaction::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) |
|
569 { |
|
570 // log the event code |
|
571 THTTPEvent receivedError = aEvent; |
|
572 |
|
573 Machine()->SetErrorDefine(iTransactionName, receivedError.iStatus); |
|
574 |
|
575 if (aEvent.iStatus < 0) |
|
576 { |
|
577 WriteDateStamp(); |
|
578 |
|
579 switch (aEvent.iStatus) |
|
580 { |
|
581 case KErrEtelNoAnswer : |
|
582 Log(_L("CCmdTransaction::MHFRunL(%S) - No Answer! Has the RAS or Internet Connection been enabled???"), &iTransactionName); |
|
583 break; |
|
584 case -3606 : |
|
585 Log(_L("CCmdTransaction::MHFRunL(%S) - Not able to make connection due to invalid or undefined COMMSDB configuration"), &iTransactionName); |
|
586 break; |
|
587 case KErrHttpGeneralHeaderMissingHost : |
|
588 Log(_L("CCmdTransaction::MHFRunL(%S) - General Header missing host information"), &iTransactionName); |
|
589 break; |
|
590 case KErrHttpCantResetRequestBody : |
|
591 Log(_L("CCmdTransaction::MHFRunL(%S) - Cannot reset request body. Redirect received"), &iTransactionName); |
|
592 break; |
|
593 case KErrHttpInvalidHeaderInRequest : |
|
594 Log(_L("CCmdTransaction::MHFRunL(%S) - Invalid Header in Request"), &iTransactionName); |
|
595 break; |
|
596 case KErrHttpEncodeUserAgent : |
|
597 Log(_L("CCmdTransaction::MHFRunL(%S) - Invalid Encode User Agent Header in Request"), &iTransactionName); |
|
598 break; |
|
599 default : |
|
600 Log(_L("CCmdTransaction::MHFRunL(%S) - The error [%d] was unexpected"), &iTransactionName, aEvent.iStatus); |
|
601 break; |
|
602 } |
|
603 |
|
604 return; |
|
605 } |
|
606 |
|
607 |
|
608 TInt statusCode = aTransaction.Response().StatusCode(); |
|
609 |
|
610 WriteDateStamp(); |
|
611 |
|
612 Log(_L("CCmdTransaction::MHFRunL( %S: Event Status Code: %d"), &iTransactionName, statusCode); |
|
613 |
|
614 Machine()->SetResultDefine(iTransactionName, statusCode); |
|
615 |
|
616 switch (aEvent.iStatus) |
|
617 { |
|
618 // The transaction's response is complete |
|
619 case THTTPEvent::EResponseComplete: |
|
620 Log(_L("(%S) : EResponseComplete received (Event Status: %d)"),&iTransactionName, aEvent.iStatus); |
|
621 break; |
|
622 |
|
623 // transaction completed (and successful) |
|
624 case THTTPEvent::ESucceeded: |
|
625 Log(_L("(%S) : ESucceeded received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
626 CloseTransaction(); |
|
627 break; |
|
628 |
|
629 // transaction completed (and successful) |
|
630 case THTTPEvent::EFailed: |
|
631 Log(_L("(%S) : Transaction EFailed received (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
632 CloseTransaction(); |
|
633 //Validate(aTransaction); |
|
634 break; |
|
635 |
|
636 case THTTPEvent::EGotResponseHeaders: |
|
637 { |
|
638 // HTTP response headers have been received |
|
639 Log(_L("(%S) : EGotResponseHeaders (%d)"),&iTransactionName, aEvent.iStatus); |
|
640 |
|
641 //TInt statusCode = aTransaction.Response().StatusCode(); |
|
642 //Log(_L("Status Code: %d "), statusCode); |
|
643 //SetCompletionCode(statusCode); |
|
644 DumpRespHeaders(aTransaction); |
|
645 } |
|
646 break; |
|
647 |
|
648 case THTTPEvent::EGotResponseBodyData: |
|
649 { |
|
650 // Some (more) body data has been received (in the HTTP response) |
|
651 Log(_L("(%S) : EGotResponseBodyData received (Event Status: %d"), &iTransactionName, aEvent.iStatus); |
|
652 |
|
653 // for each chunk of data received we have to empty the buffer before to be able to receive |
|
654 MHTTPDataSupplier *body = aTransaction.Response().Body(); |
|
655 body->ReleaseData(); |
|
656 } |
|
657 break; |
|
658 |
|
659 case KErrHttpRequestHasBody: |
|
660 Log(_L("(%S) : KErrHttpRequestHasBody received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
661 break; |
|
662 |
|
663 case KErrHttpEntityHeaderMissingContentType: |
|
664 Log(_L("(%S) : KErrHttpEntityHeaderMissingContentType received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
665 break; |
|
666 |
|
667 case KErrHttpRequestBodyMissing: |
|
668 Log(_L("(%S) : KErrHttpRequestBodyMissing received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
669 break; |
|
670 |
|
671 case KErrTimedOut: //-33 |
|
672 Log(_L("(%S) : KErrTimedOut received from the VF (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
673 break; |
|
674 |
|
675 case KErrHttpRedirectExceededLimit: |
|
676 Log(_L("(%S) : KErrHttpRedirectExceededLimit received (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
677 break; |
|
678 |
|
679 case KErrHttpRedirectNoLocationField: |
|
680 Log(_L("(%S) : KErrHttpRedirectNoLocationField received (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
681 break; |
|
682 |
|
683 default: |
|
684 Log(_L("(%S) : unrecognised event> (Event Status: %d)"), &iTransactionName, aEvent.iStatus); |
|
685 if (aEvent.iStatus < THTTPEvent::ERedirectedPermanently) |
|
686 { |
|
687 Log(_L("Test Failed: The event received was not expected and it's not just a warning")); |
|
688 } |
|
689 break; |
|
690 } |
|
691 |
|
692 if (receivedError == THTTPEvent::EResponseComplete) |
|
693 { |
|
694 Log(_L("CCmdTransaction::MHFRunL (%S) receivedError == EResponseComplete"), &iTransactionName); |
|
695 } |
|
696 else if (receivedError == THTTPEvent::ESucceeded) |
|
697 { |
|
698 Log(_L("CCmdTransaction::MHFRunL (%S) : receivedError == ESucceeded"), &iTransactionName); |
|
699 // Machine()->Domains()->Delete(transNameValueBuf); |
|
700 DoneWaitEvents(); |
|
701 } |
|
702 else if (receivedError == THTTPEvent::EFailed) |
|
703 { |
|
704 // Machine()->Domains()->Delete(transNameValueBuf); |
|
705 DoneWaitEvents(); |
|
706 } |
|
707 else |
|
708 { |
|
709 // Log(_L("CCmdTransaction::MHFRunL : (%S) iTestFail is TRUE"), &transNameValueBuf); |
|
710 DoneWaitEvents(); |
|
711 } |
|
712 } |
|
713 |
|
714 //----------------------------------------------------------------------------- |
|
715 // End of File |
|
716 //----------------------------------------------------------------------------- |
|
717 |