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