| author | Sebastian Brannstrom <sebastianb@symbian.org> | 
| Wed, 14 Jul 2010 14:53:21 +0100 | |
| changeset 180 | 74d497f911e0 | 
| parent 172 | c2a99fe1afd0 | 
| child 228 | c553fa9dcbe5 | 
| child 256 | 572d166c9421 | 
| permissions | -rw-r--r-- | 
| 2 | 1 | /* | 
| 2 | * Copyright (c) 2007-2010 Sebastian Brannstrom, Lars Persson, EmbedDev AB | |
| 3 | * | |
| 4 | * All rights reserved. | |
| 5 | * This component and the accompanying materials are made available | |
| 6 | * under the terms of the License "Eclipse Public License v1.0" | |
| 7 | * which accompanies this distribution, and is available | |
| 8 | * at the URL "http://www.eclipse.org/legal/epl-v10.html". | |
| 9 | * | |
| 10 | * Initial Contributors: | |
| 11 | * EmbedDev AB - initial contribution. | |
| 12 | * | |
| 13 | * Contributors: | |
| 14 | * | |
| 15 | * Description: | |
| 16 | * | |
| 17 | */ | |
| 18 | ||
| 19 | // HttpEventHandler.cpp | |
| 20 | #include <e32debug.h> | |
| 21 | #include <httperr.h> | |
| 22 | #include "HttpEventHandler.h" | |
| 23 | #include "bautils.h" | |
| 24 | #include "Httpclient.h" | |
| 25 | ||
| 26 | void CHttpEventHandler::ConstructL() | |
| 27 | 	{
 | |
| 28 | //iVerbose = ETrue; | |
| 29 | } | |
| 30 | ||
| 31 | ||
| 32 | CHttpEventHandler::CHttpEventHandler(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs): | |
| 33 | iFileServ(aFs), iHttpClient(aClient), iCallbacks(aCallbacks) | |
| 34 | 	{
 | |
| 35 | } | |
| 36 | ||
| 37 | ||
| 38 | CHttpEventHandler::~CHttpEventHandler() | |
| 39 | 	{	
 | |
| 40 | } | |
| 41 | ||
| 42 | ||
| 43 | CHttpEventHandler* CHttpEventHandler::NewLC(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) | |
| 44 | 	{
 | |
| 45 | CHttpEventHandler* me = new(ELeave)CHttpEventHandler(aClient, aCallbacks, aFs); | |
| 46 | CleanupStack::PushL(me); | |
| 47 | me->ConstructL(); | |
| 48 | return me; | |
| 49 | } | |
| 50 | ||
| 51 | ||
| 52 | CHttpEventHandler* CHttpEventHandler::NewL(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs) | |
| 53 | 	{
 | |
| 54 | CHttpEventHandler* me = NewLC(aClient, aCallbacks, aFs); | |
| 55 | CleanupStack::Pop(me); | |
| 56 | return me; | |
| 57 | } | |
| 58 | ||
| 59 | void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent) | |
| 60 | 	{
 | |
| 61 | switch (aEvent.iStatus) | |
| 62 | 		{
 | |
| 63 | case THTTPEvent::EGotResponseHeaders: | |
| 64 | 			{
 | |
| 65 | // HTTP response headers have been received. We can determine now if there is | |
| 66 | // going to be a response body to save. | |
| 67 | RHTTPResponse resp = aTransaction.Response(); | |
| 68 | iLastStatusCode = resp.StatusCode(); | |
| 119 
a2933afe16a7
Fix for bug 2488: RHTTPResponse::StatusText returns KNullDesc for 404 for FeedBurner, but this text was only used in debug output.
 teknolog parents: 
117diff
changeset | 69 | 			DP1("Status: %d", iLastStatusCode);
 | 
| 2 | 70 | |
| 71 | // Dump the headers if we're being verbose | |
| 72 | //DumpRespHeadersL(aTransaction); | |
| 73 | ||
| 74 | if (resp.HasBody() && (iLastStatusCode >= 200) && (iLastStatusCode < 300) && (iLastStatusCode != 204)) | |
| 75 | 				{
 | |
| 76 | TInt dataSize = resp.Body()->OverallDataSize(); | |
| 77 | 				if (dataSize >= 0) {
 | |
| 78 | 					DP1("Response body size is %d", dataSize);
 | |
| 79 | iBytesTotal = dataSize; | |
| 80 | 				} else {
 | |
| 81 | 					DP("Response body size is unknown");
 | |
| 82 | iBytesTotal = -1; | |
| 83 | } | |
| 84 | iCallbacks.DownloadInfo(iHttpClient, dataSize); | |
| 85 | ||
| 86 | } | |
| 87 | ||
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 88 | 			DP1("iFileOpen=%d", iFileOpen);
 | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 89 | if (!iFileOpen) | 
| 2 | 90 | 				{
 | 
| 91 | iFileServ.Parse(iFileName, iParsedFileName); | |
| 92 | TInt valid = iFileServ.IsValidName(iFileName); | |
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 93 | |
| 2 | 94 | if (!valid) | 
| 95 | 					{
 | |
| 96 | 					DP("The specified filename is not valid!.");
 | |
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 97 | iHttpClient->ClientRequestCompleteL(KErrBadName); | 
| 2 | 98 | } | 
| 99 | else | |
| 100 | 					{
 | |
| 101 | 					if (iContinue) {
 | |
| 102 | TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite); | |
| 103 | if (err) | |
| 104 | 							{
 | |
| 163 
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
126diff
changeset | 105 | 							DP2("There was an error=%d opening file '%S'", err, &iParsedFileName.FullName());
 | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 106 | iHttpClient->ClientRequestCompleteL(KErrInUse); | 
| 2 | 107 | User::Leave(err); | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 108 | } | 
| 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 109 | else | 
| 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 110 | 							{
 | 
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 111 | iFileOpen = ETrue; | 
| 2 | 112 | int pos = -KByteOverlap; | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 113 | if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone) | 
| 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 114 | 								{
 | 
| 2 | 115 | 								DP("Failed to set position!");
 | 
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 116 | iHttpClient->ClientRequestCompleteL(KErrWrite); | 
| 2 | 117 | User::Leave(err); | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 118 | } | 
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 119 | iBytesDownloaded = (pos > 0) ? pos : 0; | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 120 | iBytesTotal += iBytesDownloaded; | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 121 | 							DP1("Total bytes is now %u", iBytesTotal);
 | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 122 | 							DP1("Seeking end: %d", pos);
 | 
| 2 | 123 | } | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 124 | } | 
| 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 125 | else | 
| 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 126 | 						{
 | 
| 2 | 127 | TInt err = iRespBodyFile.Replace(iFileServ, | 
| 128 | iParsedFileName.FullName(), | |
| 129 | EFileWrite); | |
| 130 | if (err) | |
| 131 | 							{
 | |
| 132 | 							DP("There was an error replacing file");
 | |
| 133 | User::Leave(err); | |
| 134 | } | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 135 | else | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 136 | 							{
 | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 137 | iFileOpen = ETrue; | 
| 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 138 | } | 
| 2 | 139 | } | 
| 140 | } | |
| 141 | } | |
| 142 | } break; | |
| 143 | case THTTPEvent::EGotResponseBodyData: | |
| 144 | 			{
 | |
| 145 | // Get the body data supplier | |
| 146 | iRespBody = aTransaction.Response().Body(); | |
| 147 | ||
| 148 | // Some (more) body data has been received (in the HTTP response) | |
| 149 | //DumpRespBody(aTransaction); | |
| 150 | 			//DP1("Saving: %d", iSavingResponseBody);
 | |
| 151 | // Append to the output file if we're saving responses | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 152 | if (iFileOpen) | 
| 2 | 153 | 				{
 | 
| 154 | TPtrC8 bodyData; | |
| 155 | iRespBody->GetNextDataPart(bodyData); | |
| 156 | iBytesDownloaded += bodyData.Length(); | |
| 157 | TInt error = iRespBodyFile.Write(bodyData); | |
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 158 | |
| 2 | 159 | // on writing error we close connection | 
| 160 | 				if (error != KErrNone) {
 | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 161 | iFileOpen = EFalse; | 
| 115 
d87e984bd8b8
Even more robustness improvements for HTTP client - specifically disk full problems
 teknolog parents: 
2diff
changeset | 162 | iRespBodyFile.Close(); | 
| 2 | 163 | iCallbacks.FileError(error); | 
| 164 | iHttpClient->ClientRequestCompleteL(error); | |
| 165 | return; | |
| 166 | } | |
| 167 | ||
| 168 | 				if (!iSilent) {
 | |
| 169 | iCallbacks.Progress(iHttpClient, iBytesDownloaded, iBytesTotal); | |
| 170 | } | |
| 171 | } | |
| 172 | ||
| 173 | // Done with that bit of body data | |
| 174 | iRespBody->ReleaseData(); | |
| 175 | } break; | |
| 176 | case THTTPEvent::EResponseComplete: | |
| 177 | 			{
 | |
| 178 | // The transaction's response is complete | |
| 179 | 			DP("Transaction Complete");
 | |
| 180 | 			DP("Closing file");
 | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 181 | iFileOpen = EFalse; | 
| 2 | 182 | iRespBodyFile.Close(); | 
| 183 | } break; | |
| 184 | case THTTPEvent::ESucceeded: | |
| 185 | 			{
 | |
| 186 | 			DP("Transaction Successful");
 | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 187 | iFileOpen = EFalse; | 
| 126 | 188 | iRespBodyFile.Close(); | 
| 2 | 189 | aTransaction.Close(); | 
| 190 | iHttpClient->ClientRequestCompleteL(KErrNone); | |
| 191 | } break; | |
| 192 | case THTTPEvent::EFailed: | |
| 193 | 			{
 | |
| 194 | 			DP("Transaction Failed");
 | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 195 | iFileOpen = EFalse; | 
| 126 | 196 | iRespBodyFile.Close(); | 
| 2 | 197 | aTransaction.Close(); | 
| 198 | ||
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 199 | if(iLastStatusCode == HTTPStatus::EOk || iLastStatusCode == HTTPStatus::ECreated || iLastStatusCode == HTTPStatus::EAccepted) | 
| 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 200 | 				{
 | 
| 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 201 | iLastStatusCode = KErrNone; | 
| 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 202 | } | 
| 2 | 203 | |
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 204 | iHttpClient->ClientRequestCompleteL(iLastStatusCode); | 
| 2 | 205 | } break; | 
| 206 | case THTTPEvent::ERedirectedPermanently: | |
| 207 | 			{
 | |
| 208 | 			DP("Permanent Redirection");
 | |
| 209 | } break; | |
| 210 | case THTTPEvent::ERedirectedTemporarily: | |
| 211 | 			{
 | |
| 212 | 			DP("Temporary Redirection");
 | |
| 213 | } break; | |
| 214 | default: | |
| 215 | 			{
 | |
| 216 | 			DP1("<unrecognised event: %d>", aEvent.iStatus);
 | |
| 217 | // close off the transaction if it's an error | |
| 218 | if (aEvent.iStatus < 0) | |
| 219 | 				{
 | |
| 172 
c2a99fe1afd0
Proposed fix for bug 2931
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
163diff
changeset | 220 | iFileOpen = EFalse; | 
| 126 | 221 | iRespBodyFile.Close(); | 
| 2 | 222 | aTransaction.Close(); | 
| 223 | iHttpClient->ClientRequestCompleteL(aEvent.iStatus); | |
| 224 | } | |
| 225 | } break; | |
| 226 | } | |
| 227 | } | |
| 228 | ||
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 229 | TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/) | 
| 2 | 230 | 	{
 | 
| 231 | 	DP1("MHFRunError fired with error code %d", aError);
 | |
| 117 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 232 | aTransaction.Close(); | 
| 
3b59b88b089e
Fixed Code Scanner L-issues; Further improvements to HTTP robustness
 teknolog parents: 
116diff
changeset | 233 | TRAP_IGNORE(iHttpClient->ClientRequestCompleteL(aError)); | 
| 2 | 234 | return KErrNone; | 
| 235 | } | |
| 236 | ||
| 237 | void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue) | |
| 238 | 	{
 | |
| 163 
f94dbd678dda
Fix for bug 3183; merging minor differences with symbian1 branch
 Sebastian Brannstrom <sebastianb@symbian.org> parents: 
126diff
changeset | 239 | 	DP1("CHttpEventHandler::SetSaveFileName, aContinue=%d", aContinue);
 | 
| 2 | 240 | iFileName.Copy(fName); | 
| 241 | iContinue = aContinue; | |
| 242 | } | |
| 243 | ||
| 244 | void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans) | |
| 245 | 	{
 | |
| 246 | RHTTPResponse resp = aTrans.Response(); | |
| 247 | RStringPool strP = aTrans.Session().StringPool(); | |
| 248 | RHTTPHeaders hdr = resp.GetHeaderCollection(); | |
| 249 | THTTPHdrFieldIter it = hdr.Fields(); | |
| 250 | ||
| 251 | TBuf<KMaxHeaderNameLen> fieldName16; | |
| 252 | TBuf<KMaxHeaderValueLen> fieldVal16; | |
| 253 | ||
| 254 | while (it.AtEnd() == EFalse) | |
| 255 | 		{
 | |
| 256 | RStringTokenF fieldName = it(); | |
| 257 | RStringF fieldNameStr = strP.StringF(fieldName); | |
| 258 | THTTPHdrVal fieldVal; | |
| 259 | if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone) | |
| 260 | 			{
 | |
| 261 | const TDesC8& fieldNameDesC = fieldNameStr.DesC(); | |
| 262 | fieldName16.Copy(fieldNameDesC.Left(KMaxHeaderNameLen)); | |
| 263 | switch (fieldVal.Type()) | |
| 264 | 				{
 | |
| 265 | case THTTPHdrVal::KTIntVal: | |
| 266 | 				DP2("%S: %d", &fieldName16, fieldVal.Int());
 | |
| 267 | break; | |
| 268 | case THTTPHdrVal::KStrFVal: | |
| 269 | 				{
 | |
| 270 | RStringF fieldValStr = strP.StringF(fieldVal.StrF()); | |
| 271 | const TDesC8& fieldValDesC = fieldValStr.DesC(); | |
| 272 | fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); | |
| 273 | 				DP2("%S: %S", &fieldName16, &fieldVal16);
 | |
| 274 | } | |
| 275 | break; | |
| 276 | case THTTPHdrVal::KStrVal: | |
| 277 | 				{
 | |
| 278 | RString fieldValStr = strP.String(fieldVal.Str()); | |
| 279 | const TDesC8& fieldValDesC = fieldValStr.DesC(); | |
| 280 | fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen)); | |
| 281 | 				DP2("%S: %S", &fieldName16, &fieldVal16);
 | |
| 282 | } | |
| 283 | break; | |
| 284 | case THTTPHdrVal::KDateVal: | |
| 285 | 				{
 | |
| 286 | TDateTime date = fieldVal.DateTime(); | |
| 287 | } | |
| 288 | break; | |
| 289 | default: | |
| 290 | 				DP1("%S: <unrecognised value type>", &fieldName16);
 | |
| 291 | break; | |
| 292 | } | |
| 293 | ||
| 294 | // Display realm for WWW-Authenticate header | |
| 295 | RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable()); | |
| 296 | if (fieldNameStr == wwwAuth) | |
| 297 | 				{
 | |
| 298 | // check the auth scheme is 'basic' | |
| 299 | RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable()); | |
| 300 | RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable()); | |
| 301 | THTTPHdrVal realmVal; | |
| 302 | if ((fieldVal.StrF() == basic) && | |
| 303 | (!hdr.GetParam(wwwAuth, realm, realmVal))) | |
| 304 | 					{
 | |
| 305 | RStringF realmValStr = strP.StringF(realmVal.StrF()); | |
| 306 | fieldVal16.Copy(realmValStr.DesC()); | |
| 307 | 					DP1("Realm is: %S", &fieldVal16);
 | |
| 308 | } | |
| 309 | } | |
| 310 | } | |
| 311 | ++it; | |
| 312 | } | |
| 313 | } | |
| 314 | ||
| 315 | void CHttpEventHandler::DumpRespBody(RHTTPTransaction& aTrans) | |
| 316 | 	{
 | |
| 317 | MHTTPDataSupplier* body = aTrans.Response().Body(); | |
| 318 | TPtrC8 dataChunk; | |
| 319 | TBool isLast = body->GetNextDataPart(dataChunk); | |
| 320 | DumpIt(dataChunk); | |
| 321 | if (isLast) | |
| 322 | 		DP("Got last data chunk.");
 | |
| 323 | } | |
| 324 | ||
| 325 | ||
| 326 | void CHttpEventHandler::DumpIt(const TDesC8& aData) | |
| 327 | //Do a formatted dump of binary data | |
| 328 | 	{
 | |
| 329 | // Iterate the supplied block of data in blocks of cols=80 bytes | |
| 330 | const TInt cols=16; | |
| 331 | TInt pos = 0; | |
| 332 | TBuf<KMaxFileName - 2> logLine; | |
| 333 | TBuf<KMaxFileName - 2> anEntry; | |
| 334 | const TInt dataLength = aData.Length(); | |
| 335 | ||
| 336 | while (pos < dataLength) | |
| 337 | 		{
 | |
| 338 | //start-line hexadecimal( a 4 digit number) | |
| 339 | 		anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
 | |
| 340 | logLine.Append(anEntry); | |
| 341 | ||
| 342 | // Hex output | |
| 343 | TInt offset; | |
| 344 | for (offset = 0; offset < cols; ++offset) | |
| 345 | 			{
 | |
| 346 | if (pos + offset < aData.Length()) | |
| 347 | 				{
 | |
| 348 | TInt nextByte = aData[pos + offset]; | |
| 349 | 				anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
 | |
| 350 | logLine.Append(anEntry); | |
| 351 | } | |
| 352 | else | |
| 353 | 				{
 | |
| 354 | //fill the remaining spaces with blanks untill the cols-th Hex number | |
| 355 | 				anEntry.Format(TRefByValue<const TDesC>_L("   "));
 | |
| 356 | logLine.Append(anEntry); | |
| 357 | } | |
| 358 | } | |
| 359 | 			anEntry.Format(TRefByValue<const TDesC>_L(": "));
 | |
| 360 | logLine.Append(anEntry); | |
| 361 | ||
| 362 | // Char output | |
| 363 | for (offset = 0; offset < cols; ++offset) | |
| 364 | 			{
 | |
| 365 | if (pos + offset < aData.Length()) | |
| 366 | 				{
 | |
| 367 | TInt nextByte = aData[pos + offset]; | |
| 368 | if ((nextByte >= ' ') && (nextByte <= '~')) | |
| 369 | 					{
 | |
| 370 | 					anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
 | |
| 371 | logLine.Append(anEntry); | |
| 372 | } | |
| 373 | else | |
| 374 | 					{
 | |
| 375 | 					anEntry.Format(TRefByValue<const TDesC>_L("."));
 | |
| 376 | logLine.Append(anEntry); | |
| 377 | } | |
| 378 | } | |
| 379 | else | |
| 380 | 				{
 | |
| 381 | 				anEntry.Format(TRefByValue<const TDesC>_L(" "));
 | |
| 382 | logLine.Append(anEntry); | |
| 383 | } | |
| 384 | } | |
| 385 | logLine.Zero(); | |
| 386 | ||
| 387 | // Advance to next byte segment (1 seg= cols) | |
| 388 | pos += cols; | |
| 389 | } | |
| 390 | } | |
| 391 | ||
| 392 | void CHttpEventHandler::SetSilent(TBool aSilent) | |
| 393 | 	{
 | |
| 394 | iSilent = aSilent; | |
| 395 | } | |
| 396 | ||
| 397 | void CHttpEventHandler::CloseSaveFile() | |
| 398 | {
 | |
| 399 | if(iRespBody != NULL) | |
| 400 | 	{		
 | |
| 401 | if(iRespBodyFile.SubSessionHandle() != 0) | |
| 402 | 			{
 | |
| 403 | TInt size; | |
| 404 | iRespBodyFile.Size(size); | |
| 405 | 			DP2("Closing file at size %d, bytes downloaded %d", size, iBytesDownloaded);
 | |
| 406 | iRespBodyFile.Close(); | |
| 407 | } | |
| 408 | } | |
| 409 | } | |
| 410 |