engine/src/HttpEventHandler.cpp
author Sebastian Brannstrom <sebastianb@symbian.org>
Sun, 24 Oct 2010 01:27:31 +0100
branchRCL_3
changeset 285 4d42a5e09930
parent 256 572d166c9421
child 305 dc1c3d779802
permissions -rw-r--r--
Significant robustness improvements for ConnectionEngine
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>
256
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
    22
#include <sysutil.h>
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    23
#include "HttpEventHandler.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    24
#include "bautils.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    25
#include "Httpclient.h"
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    26
256
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
    27
const TInt64 KMinDiskSpace = 1024 * 1024; // at least 1 MB must remain
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
    28
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    29
void CHttpEventHandler::ConstructL()
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
	//iVerbose = ETrue;	
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    32
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    33
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
CHttpEventHandler::CHttpEventHandler(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs): 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    36
	iFileServ(aFs), iHttpClient(aClient), iCallbacks(aCallbacks)
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
	}
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
CHttpEventHandler::~CHttpEventHandler()
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
	}
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    46
CHttpEventHandler* CHttpEventHandler::NewLC(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    47
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    48
	CHttpEventHandler* me = new(ELeave)CHttpEventHandler(aClient, aCallbacks, aFs);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    49
	CleanupStack::PushL(me);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    50
	me->ConstructL();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    51
	return me;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    52
	}
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    55
CHttpEventHandler* CHttpEventHandler::NewL(CHttpClient* aClient, MHttpClientObserver &aCallbacks, RFs& aFs)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    56
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    57
	CHttpEventHandler* me = NewLC(aClient, aCallbacks, aFs);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    58
	CleanupStack::Pop(me);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    59
	return me;
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
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    62
void CHttpEventHandler::MHFRunL(RHTTPTransaction aTransaction, const THTTPEvent& aEvent)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    63
	{
285
4d42a5e09930 Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 256
diff changeset
    64
	DP1("CHttpEventHandler::MHFRunL, aEvent.iStatus=%d", aEvent.iStatus);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    65
	switch (aEvent.iStatus)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    66
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    67
		case THTTPEvent::EGotResponseHeaders:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    68
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    69
			// 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
    70
			// going to be a response body to save.
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    71
			RHTTPResponse resp = aTransaction.Response();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    72
			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
    73
			DP1("Status: %d", iLastStatusCode);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    74
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    75
			// Dump the headers if we're being verbose
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    76
			//DumpRespHeadersL(aTransaction);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    77
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    78
			if (resp.HasBody() && (iLastStatusCode >= 200) && (iLastStatusCode < 300) && (iLastStatusCode != 204))
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    79
				{
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
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    91
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
    92
			DP1("iFileOpen=%d", iFileOpen);
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
    93
			if (!iFileOpen)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    94
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    95
				iFileServ.Parse(iFileName, iParsedFileName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    96
				TInt valid = iFileServ.IsValidName(iFileName);
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
    97
				
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
    98
				if (!valid)
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
					DP("The specified filename is not valid!.");
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   101
					iHttpClient->ClientRequestCompleteL(KErrBadName);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   102
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   103
				else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   104
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   105
					if (iContinue) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   106
						TInt err = iRespBodyFile.Open(iFileServ, iParsedFileName.FullName(),EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   107
						if (err)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   108
							{
163
f94dbd678dda Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   109
							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: 2
diff changeset
   110
							iHttpClient->ClientRequestCompleteL(KErrInUse);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   111
							User::Leave(err);
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   112
							} 
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   113
						else
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   114
							{
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   115
							iFileOpen = ETrue;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   116
							int pos = -KByteOverlap;
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   117
							if((err=iRespBodyFile.Seek(ESeekEnd, pos)) != KErrNone)
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   118
								{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   119
								DP("Failed to set position!");
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   120
								iHttpClient->ClientRequestCompleteL(KErrWrite);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   121
								User::Leave(err);
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   122
								}
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   123
							iBytesDownloaded = (pos > 0) ? pos : 0;
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   124
							iBytesTotal += iBytesDownloaded;
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   125
							DP1("Total bytes is now %u", iBytesTotal);
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   126
							DP1("Seeking end: %d", pos);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   127
							}
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   128
						}
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   129
					else 
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   130
						{
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   131
						TInt err = iRespBodyFile.Replace(iFileServ,
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   132
														 iParsedFileName.FullName(),
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   133
														 EFileWrite);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   134
						if (err)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   135
							{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   136
							DP("There was an error replacing file");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   137
							User::Leave(err);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   138
							}
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   139
						else
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   140
							{
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   141
							iFileOpen = ETrue;
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   142
							}
2
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
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   145
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   146
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   147
		case THTTPEvent::EGotResponseBodyData:
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
			// Get the body data supplier
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   150
			iRespBody = aTransaction.Response().Body();
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
			// Some (more) body data has been received (in the HTTP response)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   153
			//DumpRespBody(aTransaction);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   154
			//DP1("Saving: %d", iSavingResponseBody);
256
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   155
			
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   156
			// check if we have enough disk space
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   157
			if (iDriveNo != -1 && SysUtil::DiskSpaceBelowCriticalLevelL( &iFileServ, KMinDiskSpace, iDriveNo ))
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   158
				{
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   159
					TInt error = KErrDiskFull;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   160
					iFileOpen = EFalse;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   161
					iRespBodyFile.Close();
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   162
					iCallbacks.FileError(error);
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   163
					iHttpClient->ClientRequestCompleteL(error);
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   164
					return;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   165
				}
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   166
			
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   167
			// Append to the output file if we're saving responses
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   168
			if (iFileOpen)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   169
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   170
				TPtrC8 bodyData;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   171
				iRespBody->GetNextDataPart(bodyData);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   172
				iBytesDownloaded += bodyData.Length();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   173
				TInt error = iRespBodyFile.Write(bodyData);
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   174
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   175
				// on writing error we close connection 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   176
				if (error != KErrNone) {
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   177
					iFileOpen = EFalse;
115
d87e984bd8b8 Even more robustness improvements for HTTP client - specifically disk full problems
teknolog
parents: 2
diff changeset
   178
					iRespBodyFile.Close();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   179
					iCallbacks.FileError(error);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   180
					iHttpClient->ClientRequestCompleteL(error);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   181
					return;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   182
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   183
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   184
				if (!iSilent) {
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   185
					iCallbacks.Progress(iHttpClient, iBytesDownloaded, iBytesTotal);
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
				}
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
			// Done with that bit of body data
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   190
			iRespBody->ReleaseData();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   191
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   192
		case THTTPEvent::EResponseComplete:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   193
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   194
			// The transaction's response is complete
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   195
			DP("Transaction Complete");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   196
			DP("Closing file");
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   197
			iFileOpen = EFalse;
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   198
			iRespBodyFile.Close();
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::ESucceeded:
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 Successful");
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   203
			iFileOpen = EFalse;
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 119
diff changeset
   204
			iRespBodyFile.Close();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   205
			aTransaction.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   206
			iHttpClient->ClientRequestCompleteL(KErrNone);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   207
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   208
		case THTTPEvent::EFailed:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   209
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   210
			DP("Transaction Failed");
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   211
			iFileOpen = EFalse;
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 119
diff changeset
   212
			iRespBodyFile.Close();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   213
			aTransaction.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   214
			
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   215
			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
   216
				{
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   217
				iLastStatusCode = KErrNone;
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   218
				}
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   219
			
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   220
			iHttpClient->ClientRequestCompleteL(iLastStatusCode);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   221
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   222
		case THTTPEvent::ERedirectedPermanently:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   223
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   224
			DP("Permanent Redirection");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   225
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   226
		case THTTPEvent::ERedirectedTemporarily:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   227
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   228
			DP("Temporary Redirection");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   229
			} break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   230
		default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   231
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   232
			DP1("<unrecognised event: %d>", aEvent.iStatus);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   233
			// close off the transaction if it's an error
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   234
			if (aEvent.iStatus < 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   235
				{
172
c2a99fe1afd0 Proposed fix for bug 2931
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 163
diff changeset
   236
				iFileOpen = EFalse;
126
c2f1ea38ec70 Import from FCL default branch
teknolog
parents: 119
diff changeset
   237
				iRespBodyFile.Close();
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   238
				aTransaction.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   239
				iHttpClient->ClientRequestCompleteL(aEvent.iStatus);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   240
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   241
			} break;
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
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   244
117
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   245
TInt CHttpEventHandler::MHFRunError(TInt aError, RHTTPTransaction aTransaction, const THTTPEvent& /*aEvent*/)
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   246
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   247
	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
   248
	aTransaction.Close();
3b59b88b089e Fixed Code Scanner L-issues; Further improvements to HTTP robustness
teknolog
parents: 116
diff changeset
   249
	TRAP_IGNORE(iHttpClient->ClientRequestCompleteL(aError));
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   250
	return KErrNone;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   251
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   252
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   253
void CHttpEventHandler::SetSaveFileName(const TDesC &fName, TBool aContinue)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   254
	{
163
f94dbd678dda Fix for bug 3183; merging minor differences with symbian1 branch
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 126
diff changeset
   255
	DP1("CHttpEventHandler::SetSaveFileName, aContinue=%d", aContinue);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   256
	iFileName.Copy(fName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   257
	iContinue = aContinue;
256
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   258
	
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   259
	switch(fName[0])
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   260
		{
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   261
		case 'C':
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   262
			iDriveNo = EDriveC;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   263
			break;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   264
		case 'E':
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   265
			iDriveNo = EDriveE;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   266
			break;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   267
		case 'F':
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   268
			iDriveNo = EDriveF;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   269
			break;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   270
		case 'G':
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   271
			iDriveNo = EDriveG;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   272
			break;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   273
		default:
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   274
			iDriveNo = -1;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   275
			break;
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   276
		}
572d166c9421 Merged fix for bug 3843
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 172
diff changeset
   277
	DP1("iDriveNo set to %d", iDriveNo);
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   278
	}
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
void CHttpEventHandler::DumpRespHeadersL(RHTTPTransaction& aTrans)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   281
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   282
	RHTTPResponse resp = aTrans.Response();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   283
	RStringPool strP = aTrans.Session().StringPool();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   284
	RHTTPHeaders hdr = resp.GetHeaderCollection();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   285
	THTTPHdrFieldIter it = hdr.Fields();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   286
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   287
	TBuf<KMaxHeaderNameLen>  fieldName16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   288
	TBuf<KMaxHeaderValueLen> fieldVal16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   289
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   290
	while (it.AtEnd() == EFalse)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   291
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   292
		RStringTokenF fieldName = it();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   293
		RStringF fieldNameStr = strP.StringF(fieldName);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   294
		THTTPHdrVal fieldVal;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   295
		if (hdr.GetField(fieldNameStr,0,fieldVal) == KErrNone)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   296
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   297
			const TDesC8& fieldNameDesC = fieldNameStr.DesC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   298
			fieldName16.Copy(fieldNameDesC.Left(KMaxHeaderNameLen));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   299
			switch (fieldVal.Type())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   300
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   301
			case THTTPHdrVal::KTIntVal:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   302
				DP2("%S: %d", &fieldName16, fieldVal.Int());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   303
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   304
			case THTTPHdrVal::KStrFVal:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   305
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   306
				RStringF fieldValStr = strP.StringF(fieldVal.StrF());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   307
				const TDesC8& fieldValDesC = fieldValStr.DesC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   308
				fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   309
				DP2("%S: %S", &fieldName16, &fieldVal16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   310
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   311
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   312
			case THTTPHdrVal::KStrVal:
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
				RString fieldValStr = strP.String(fieldVal.Str());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   315
				const TDesC8& fieldValDesC = fieldValStr.DesC();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   316
				fieldVal16.Copy(fieldValDesC.Left(KMaxHeaderValueLen));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   317
				DP2("%S: %S", &fieldName16, &fieldVal16);
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
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   320
			case THTTPHdrVal::KDateVal:
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
				TDateTime date = fieldVal.DateTime();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   323
				} 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   324
				break;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   325
			default:
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   326
				DP1("%S: <unrecognised value type>", &fieldName16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   327
				break;
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
			// Display realm for WWW-Authenticate header
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   331
			RStringF wwwAuth = strP.StringF(HTTP::EWWWAuthenticate,RHTTPSession::GetTable());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   332
			if (fieldNameStr == wwwAuth)
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
				// check the auth scheme is 'basic'
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   335
				RStringF basic = strP.StringF(HTTP::EBasic,RHTTPSession::GetTable());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   336
				RStringF realm = strP.StringF(HTTP::ERealm,RHTTPSession::GetTable());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   337
				THTTPHdrVal realmVal;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   338
				if ((fieldVal.StrF() == basic) && 
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   339
					(!hdr.GetParam(wwwAuth, realm, realmVal)))
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
					RStringF realmValStr = strP.StringF(realmVal.StrF());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   342
					fieldVal16.Copy(realmValStr.DesC());
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   343
					DP1("Realm is: %S", &fieldVal16);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   344
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   345
				}
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
		++it;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   348
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   349
	}
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
void CHttpEventHandler::DumpRespBody(RHTTPTransaction& aTrans)
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
	MHTTPDataSupplier* body = aTrans.Response().Body();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   354
	TPtrC8 dataChunk;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   355
	TBool isLast = body->GetNextDataPart(dataChunk);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   356
	DumpIt(dataChunk);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   357
	if (isLast)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   358
		DP("Got last data chunk.");
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   359
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   360
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   361
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   362
void CHttpEventHandler::DumpIt(const TDesC8& aData)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   363
//Do a formatted dump of binary data
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   364
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   365
	// 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
   366
	const TInt cols=16;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   367
	TInt pos = 0;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   368
	TBuf<KMaxFileName - 2> logLine;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   369
	TBuf<KMaxFileName - 2> anEntry;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   370
	const TInt dataLength = 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
	while (pos < dataLength)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   373
		{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   374
		//start-line hexadecimal( a 4 digit number)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   375
		anEntry.Format(TRefByValue<const TDesC>_L("%04x : "), pos);
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
		// Hex output
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   379
		TInt offset;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   380
		for (offset = 0; offset < cols; ++offset)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   381
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   382
			if (pos + offset < aData.Length())
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
				TInt nextByte = aData[pos + offset];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   385
				anEntry.Format(TRefByValue<const TDesC>_L("%02x "), nextByte);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   386
				logLine.Append(anEntry);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   387
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   388
			else
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
				//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
   391
				anEntry.Format(TRefByValue<const TDesC>_L("   "));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   392
				logLine.Append(anEntry);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   393
				}
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
			anEntry.Format(TRefByValue<const TDesC>_L(": "));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   396
			logLine.Append(anEntry);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   397
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   398
		// Char output
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   399
		for (offset = 0; offset < cols; ++offset)
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
			if (pos + offset < aData.Length())
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   402
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   403
				TInt nextByte = aData[pos + offset];
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   404
				if ((nextByte >= ' ') && (nextByte <= '~'))
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
					anEntry.Format(TRefByValue<const TDesC>_L("%c"), nextByte);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   407
					logLine.Append(anEntry);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   408
					}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   409
				else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   410
					{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   411
					anEntry.Format(TRefByValue<const TDesC>_L("."));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   412
					logLine.Append(anEntry);
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
			else
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   416
				{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   417
				anEntry.Format(TRefByValue<const TDesC>_L(" "));
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   418
				logLine.Append(anEntry);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   419
				}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   420
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   421
			logLine.Zero();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   422
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   423
		// Advance to next  byte segment (1 seg= cols)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   424
		pos += cols;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   425
		}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   426
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   427
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   428
void CHttpEventHandler::SetSilent(TBool aSilent)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   429
	{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   430
	iSilent = aSilent;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   431
	}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   432
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   433
void CHttpEventHandler::CloseSaveFile()
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   434
{
285
4d42a5e09930 Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 256
diff changeset
   435
	DP("CHttpEventHandler::CloseSaveFile BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   436
	if(iRespBody != NULL)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   437
	{		
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   438
		if(iRespBodyFile.SubSessionHandle() != 0)
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   439
			{
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   440
			TInt size;
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   441
			iRespBodyFile.Size(size);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   442
			DP2("Closing file at size %d, bytes downloaded %d", size, iBytesDownloaded);
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   443
			iRespBodyFile.Close();
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   444
			}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   445
	}
285
4d42a5e09930 Significant robustness improvements for ConnectionEngine
Sebastian Brannstrom <sebastianb@symbian.org>
parents: 256
diff changeset
   446
	DP("CHttpEventHandler::CloseSaveFile BEGIN");
2
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   447
}
29cda98b007e Initial import of Podcatcher from the Bergamot project
skip
parents:
diff changeset
   448